Fix regex in strip_trailing_url_punctuation to properly escape special characters
- Corrected the regular expression in the `strip_trailing_url_punctuation` function to properly escape the single quote (') and ensure valid syntax.
- Fixed potential issues caused by unescaped characters in the regex pattern.
This commit is contained in:
26
rss2bsky.py
26
rss2bsky.py
@@ -419,26 +419,26 @@ def build_post_text_variants(title_text: str, link: str, max_length: int = 300):
|
||||
full = f"{title_text}\n\n{link}"
|
||||
if len(full) <= max_length:
|
||||
add_variant(full)
|
||||
else:
|
||||
# Trunca el títol per fer-hi lloc al link
|
||||
# Reserva espai per "\n\n" + link
|
||||
reserve = len(link) + 2
|
||||
available = max_length - reserve
|
||||
if available > 20:
|
||||
# FIX: Use single char '…' and strip trailing dots/spaces
|
||||
truncated_title = title_text[:available].rstrip(" .")
|
||||
add_variant(f"{truncated_title}\n\n{link}")
|
||||
|
||||
# Variant 2: només títol (truncat si cal)
|
||||
# Variant 2: només títol complet (sense truncar)
|
||||
if title_text:
|
||||
if len(title_text) <= max_length:
|
||||
add_variant(title_text)
|
||||
else:
|
||||
# FIX: Use single char '…' and strip trailing dots/spaces
|
||||
truncated = title_text[:max_length - 1].rstrip(" .")
|
||||
truncated = title_text[:max_length].rstrip(" .")
|
||||
add_variant(truncated)
|
||||
|
||||
# Variant 3: només link (si no hi ha títol)
|
||||
# Variant 3: títol truncat + link (si el títol complet+link no hi cap)
|
||||
if title_text and link:
|
||||
full = f"{title_text}\n\n{link}"
|
||||
if len(full) > max_length:
|
||||
reserve = len(link) + 2
|
||||
available = max_length - reserve
|
||||
if available > 20:
|
||||
truncated_title = title_text[:available].rstrip(" .")
|
||||
add_variant(f"{truncated_title}\n\n{link}")
|
||||
|
||||
# Variant 4: només link (si no hi ha títol)
|
||||
if link and not title_text:
|
||||
add_variant(link)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user