Skip to content

Commit a54062f

Browse files
author
Clément VÉRET
committed
fix: detect parenthesis independently from punctuation ending links
1 parent d02f0a2 commit a54062f

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

bsky-sdk/src/rich_text/detection.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ pub fn detect_facets(text: &str) -> Vec<FacetWithoutResolution> {
7070
};
7171
let mut index = ByteSliceData { byte_end: m.end(), byte_start: m.start() };
7272
// strip ending punctuation
73-
if (re_ending_punctuation.is_match(&uri)) || (uri.ends_with(')') && !uri.contains('('))
74-
{
73+
if re_ending_punctuation.is_match(&uri) {
74+
uri.pop();
75+
index.byte_end -= 1;
76+
}
77+
if uri.ends_with(')') && !uri.contains('(') {
7578
uri.pop();
7679
index.byte_end -= 1;
7780
}

bsky-sdk/src/rich_text/tests/detection.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ async fn detect_facets_mentions_and_links() -> Result<()> {
249249
(")", None),
250250
],
251251
),
252+
(
253+
"parenthentical with commas (https://foo.com), knowing that https://bar.com",
254+
vec![
255+
("parenthentical with commas (", None),
256+
("https://foo.com", Some("https://foo.com")),
257+
("), knowing that ", None),
258+
("https://bar.com", Some("https://bar.com")),
259+
],
260+
),
252261
(
253262
"except for https://foo.com/thing_(cool)",
254263
vec![

0 commit comments

Comments
 (0)