jekyll-target-blank icon indicating copy to clipboard operation
jekyll-target-blank copied to clipboard

Add support for Unicode links

Open mukrop opened this issue 5 years ago • 20 comments

  • In function 'external?', URI is now escaped before split.
  • This adheres to the recommendation in the URI docs: https://www.rubydoc.info/stdlib/uri/URI.parse
  • Resolves #33.

mukrop avatar Oct 27 '19 11:10 mukrop

Sorry it took so long, my past two weeks were also rather busy.

mukrop avatar Oct 27 '19 12:10 mukrop

Hi @mukrop ,

Thank for sharing your work :)

The travis checks are failing can you look into why, please?

Also, thank you for the version number :)

keithmifsud avatar Oct 30 '19 02:10 keithmifsud

The problem is that URI escape is deprecated, I suggest to use CGI.escape() instead. They do NOT behave in the same way, but in this particular case it does not matter how the URI is escaped, because this is for comparison only

lib/jekyll-target-blank.rb:196:21: W: Lint/UriEscapeUnescape: URI.escape method is obsolete and should not be used. Instead, use CGI.escape, URI.encode_www_form or URI.encode_www_form_component depending on your specific use case. 459 URI.parse(URI.escape(link)).host != URI.parse(URI.escape(@site_url)).host 460 ^^^^^^^^^^^^^^^^ 461lib/jekyll-target-blank.rb:196:57: W: Lint/UriEscapeUnescape: URI.escape method is obsolete and should not be used. Instead, use CGI.escape, URI.encode_www_form or URI.encode_www_form_component depending on your specific use case. 462 URI.parse(URI.escape(link)).host != URI.parse(URI.escape(@site_url)).host 463 ^^^^^^^^^^^^^^^^^^^^^

mcrobs avatar Feb 10 '20 16:02 mcrobs

The problem is that URI escape is deprecated, I suggest to use CGI.escape() instead. They do NOT behave in the same way, but in this particular case it does not matter how the URI is escaped, because this is for comparison only

lib/jekyll-target-blank.rb:196:21: W: Lint/UriEscapeUnescape: URI.escape method is obsolete and should not be used. Instead, use CGI.escape, URI.encode_www_form or URI.encode_www_form_component depending on your specific use case. 459 URI.parse(URI.escape(link)).host != URI.parse(URI.escape(@site_url)).host 460 ^^^^^^^^^^^^^^^^ 461lib/jekyll-target-blank.rb:196:57: W: Lint/UriEscapeUnescape: URI.escape method is obsolete and should not be used. Instead, use CGI.escape, URI.encode_www_form or URI.encode_www_form_component depending on your specific use case. 462 URI.parse(URI.escape(link)).host != URI.parse(URI.escape(@site_url)).host 463 ^^^^^^^^^^^^^^^^^^^^^

Thank you @mcrobs .. sorry for the cheeky request but is any chance you can update this PR by @mukrop to use the other parser, please?

If not I'll try to get to it asap but I'm rather busy and away from a Ruby IDE at this moment.

keithmifsud avatar Feb 13 '20 04:02 keithmifsud

I do apologize for my inactivity, but I'm rather busy now. I'd be glad if you managed to resolve this without me.

mukrop avatar Feb 13 '20 09:02 mukrop

I understand and thank you for all your help in this 😄

keithmifsud avatar Feb 25 '20 01:02 keithmifsud

@mukrop @keithmifsud polite bump :)

wbsmolen avatar Aug 28 '20 18:08 wbsmolen

Any news on this one?

rafaelbiriba avatar Nov 09 '20 13:11 rafaelbiriba

Hi. I've looked into this after a longer while. In the end, I used the Addressable class for URI parsing as

  1. URI is not capable to process non-ascii characters (see https://bugs.ruby-lang.org/issues/12852)
  2. URI.escape is deprecated
  3. Alternatives such as CGI.escape do a different thing (they escape the :// that separates the protocol and thus breaks the parsing).

The tests now pass but the build fails on not finding .rubocop_todo.yml (which I don't understand and seems unrelated).

mukrop avatar Dec 05 '20 19:12 mukrop

@mukrop can we borough a little bit of your time to see if #61 is the fix for #46? Maybe just approving 2 PRs and creating a release could help a lot of us.

jochenjonc avatar Jun 28 '22 20:06 jochenjonc

I'm off for the rest of the week but I believe I'll be able to find some time for this next week :-).

mukrop avatar Jun 29 '22 19:06 mukrop

Hi. I've tested the patch, but the issue is not fixed, the error seems the same.

/usr/lib/ruby/2.7.0/uri/rfc3986_parser.rb:21:in `split': URI must be ascii only (URI::InvalidURIError)

mukrop avatar Jul 09 '22 11:07 mukrop

Hi. I've tested the patch, but the issue is not fixed, the error seems the same.

/usr/lib/ruby/2.7.0/uri/rfc3986_parser.rb:21:in `split': URI must be ascii only (URI::InvalidURIError)

Could it be that the code or test isn't using the Addressable implementation of URI, but still the standard on of Ruby?

jochenjonc avatar Jul 09 '22 11:07 jochenjonc

Aah, sorry @jochenjonc, I misunderstood what I was supposed to check. I did it properly now and, indeed, #61 fixes the thing!

For testing purposes, I've added an extra commit to this PR replicating #61. For the sake of a clean codebase, I presume you want to merge #61 first and then merge this onto it without the replicating commit?

mukrop avatar Jul 09 '22 12:07 mukrop

@mukrop you can choose how to merge everything. None of the PRs are mine. 😉

jochenjonc avatar Jul 09 '22 14:07 jochenjonc

Oh, and you are not the repository owner either, I thought you were :-).

mukrop avatar Jul 09 '22 14:07 mukrop

Funny, I thought you where the repo owner. 🤔

jochenjonc avatar Jul 09 '22 17:07 jochenjonc

@keithmifsud are you able to merge this PR and create a new release?

jochenjonc avatar Jul 10 '22 07:07 jochenjonc

Hi @jochenjonc ..I'll merge it asap. I need to remove the Travis CI check first but they seem to have changed the access. I'll get back to you asap.

The PR looks good. Thank you :smile:

keithmifsud avatar Jul 10 '22 08:07 keithmifsud

@keithmifsud any luck on removing Travis CI check?

jochenjonc avatar Jul 25 '22 09:07 jochenjonc