Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linkify to only link to proper URLs #5920

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

perlpunk
Copy link
Contributor

@perlpunk perlpunk commented Sep 11, 2024

This doesn't check for really well formed URLs, but it limits the matching to only allowed characters in URIs.
It makes up for escapeForHtml() being already called, so it matches & separately.

Tested with:

# "> should be excluded
"https://github.com/os-autoinst/openQA.git"
<https://github.com/os-autoinst/os-autoinst.git>
# ) should be included
https://de.wikipedia.org/wiki/Queen_(Band)
# query strings should be included
https://github.com/os-autoinst/openQA?foo=1%20&bar=*2

Single quotes actually can be part of URIs so that's something we should adapt
in our code (and use double quotes, or I remember back in usenet times we used
<http://...> whenever referring to a URL in plain text).

We could use this as a workaround until an according PR to https://github.com/IonicaBizau/anser has been made.
There is a related issue: IonicaBizau/anser#63

Alternative to

Issue: https://progress.opensuse.org/issues/166676

okurz
okurz previously requested changes Sep 11, 2024
assets/javascripts/anser-import.js Outdated Show resolved Hide resolved
@perlpunk perlpunk force-pushed the fix-linkify branch 2 times, most recently from 28f5b98 to e36fd22 Compare September 11, 2024 12:06
Copy link
Member

@okurz okurz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@perlpunk
Copy link
Contributor Author

IonicaBizau/anser#75

Copy link

codecov bot commented Sep 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.73%. Comparing base (a19e2eb) to head (61be703).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5920   +/-   ##
=======================================
  Coverage   98.73%   98.73%           
=======================================
  Files         395      395           
  Lines       38764    38770    +6     
=======================================
+ Hits        38275    38281    +6     
  Misses        489      489           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Martchus Martchus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks generally good. I think this is the right approach.

@perlpunk perlpunk force-pushed the fix-linkify branch 3 times, most recently from 5f3cabc to c9721ce Compare September 11, 2024 17:04
@perlpunk perlpunk marked this pull request as ready for review September 11, 2024 17:06
@perlpunk
Copy link
Contributor Author

I added a test

This doesn't check for really well formed URLs, but it limits the matching to
only allowed characters in URIs.
It makes up for escapeForHtml() being already called, so it matches `&amp;`
separately.

Tested with:

    # "> should be excluded
    "https://github.com/os-autoinst/openQA.git"
    <https://github.com/os-autoinst/os-autoinst.git>
    # ) should be included
    https://de.wikipedia.org/wiki/Queen_(Band)
    # query strings should be included
    https://github.com/os-autoinst/openQA?foo=1%20&bar=*2

Single quotes actually can be part of URIs so that's something we should adapt
in our code (and use double quotes, or I remember back in usenet times we used
`<http://...>` whenever referring to a URL in plain text)

Issue: https://progress.opensuse.org/issues/166676
@mergify mergify bot merged commit dde1ec5 into os-autoinst:master Sep 12, 2024
45 checks passed
b10n1k added a commit to b10n1k/os-autoinst that referenced this pull request Sep 12, 2024
Solution provided on os-autoinst/openQA#5920 and
this is a adaptable change to that commit as unescaped single quotes are valid
parts of URIs

https://progress.opensuse.org/issues/166676

[0] https://github.com/IonicaBizau/anser/tree/master?tab=readme-ov-file#anserlinkifytxt

Signed-off-by: ybonatakis <[email protected]>
b10n1k added a commit to b10n1k/os-autoinst that referenced this pull request Sep 12, 2024
Solution provided on os-autoinst/openQA#5920 and
this is a adaptable change to that commit as unescaped single quotes are valid
parts of URIs

https://progress.opensuse.org/issues/166676

Signed-off-by: ybonatakis <[email protected]>
@perlpunk perlpunk deleted the fix-linkify branch September 12, 2024 15:01
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.

4 participants