Skip to content

Treat | as a stop character on the right side of URL - #171

Merged
lipoja merged 1 commit into
lipoja:masterfrom
rishisy:pipe-stop-char
Oct 2, 2026
Merged

lipoja merged 1 commit into
lipoja:masterfrom
rishisy:pipe-stop-char

Conversation

@rishisy

@rishisy rishisy commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

I ran into this while using urlextract in a project that pulls issue descriptions out of Jira. Jira stores Google Docs links as smart links in its wiki markup, and this is what one of those looked like:

h3. [https://docs.google.com/document/d/1Vtp9CUsBeORYiWuBN3qMZvgBdnZoxuwr3LAx9eP8CUc/edit?tab=t.0#heading=h.urorssaipc59|https://docs.google.com/document/d/1Vtp9CUsBeORYiWuBN3qMZvgBdnZoxuwr3LAx9eP8CUc/edit?tab=t.0#heading=h.urorssaipc59|smart-link]

On 1.9.0 find_urls() gives back a single URL that contains both copies of the link, the two pipes and the smart-link label at the end. I first thought it was something odd about the Google Docs URL, but the same thing happens with any url|label text.

The | separator is not specific to Jira. Confluence wiki markup uses [https://example.com|label], Slack uses <https://example.com|label>, MediaWiki and DokuWiki use [[https://example.com|label]]. Anyone feeding text from those tools into urlextract will hit this.

Cause

| is already in _stop_chars_left, but not in _stop_chars_right, so the right side of the URL runs through the pipe. It is also not in the set of characters allowed right after a TLD, so a bare example.com|label is rejected outright.

Change

  • Move | into general_stop_chars so it stops the URL on both sides.
  • Add | to the characters allowed after a TLD.
  • Add three test cases, one of them in the smart link shape above.
  • Add a changelog line.

Result

The Jira text above now returns two URLs, both ending before the pipe. [http://example.com|Example] returns http://example.com, and see example.com|other returns example.com.

A URL cannot contain a raw |; RFC 3986 requires it to be percent-encoded. So I do not expect this to break any valid URL. All 182 tests pass.

Jira/Confluence style links like [url|url|smart-link] were extracted as one
long URL including the pipes and the label. | was already a left stop char
but not a right one, and was not allowed right after a TLD.
@rishi-seezo

Copy link
Copy Markdown

@lipoja Hey, Could you look at this. Requesting a review.

@lipoja

lipoja commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Thank you for your contribution!
And sorry for such a late response.

@lipoja
lipoja merged commit 5fcdb89 into lipoja:master Oct 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants