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

Feat: Encode/Decode URL #905

Closed
Spsp1981 opened this issue Nov 6, 2024 · 11 comments
Closed

Feat: Encode/Decode URL #905

Spsp1981 opened this issue Nov 6, 2024 · 11 comments
Labels
💬discussion 🌐i18n Localization/Internationalization ❓question ui
Milestone

Comments

@Spsp1981
Copy link

Spsp1981 commented Nov 6, 2024

Notepad2-mod had a feature under the "Special" menu to encode/decode URLs.
Example: "https%3A%2F%2Fwww.google.com%2Fcontacts" to "https://www.google.com/contacts" and back

I'd like that function to come back

@0hip
Copy link

0hip commented Nov 6, 2024

Notepad2-mod had a feature under the "Special" menu to encode/decode URLs. Example: "https%3A%2F%2Fwww.google.com%2Fcontacts" to "https://www.google.com/contacts" and back

I'd like that function to come back

URL encode seems not working . . . but . . .
URL decode works fine!
image

image

@Spsp1981
Copy link
Author

Spsp1981 commented Nov 6, 2024

Oh!!! Absolutely my bad!!! I was used to finding those options in the Edit->Special menu and thought they were replaced by the (un)escape html/xml options. I saw the tools menu but evidently not carefully enough! Well, at least we found a bug!
Thank you very much!

@zufuliu
Copy link
Owner

zufuliu commented Nov 7, 2024

Well, at least we found a bug!

No, see issue #581 for the change.

@Spsp1981
Copy link
Author

Spsp1981 commented Nov 7, 2024

While I have my reserves regarding the difference between Decode/Encode URL and Escape/Unescape HTML which both perform their actions on selected text. I do not want to reopen that discussion. I'm glad that the functionality is present and that's good enough for me.
The bug I was talking about is the "Tools->Encode URL" not working...

@zufuliu
Copy link
Owner

zufuliu commented Nov 7, 2024

The change is from issue #315, the flag for UrlEscape() function changed from URL_ESCAPE_SEGMENT_ONLY to URL_ESCAPE_AS_UTF8 in commit e13a400.

@zufuliu
Copy link
Owner

zufuliu commented Nov 7, 2024

Based on examples from https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-urlescapew#examples, I think here are three options for URL encode:

  1. treat selected text as full URL (current behavior, URL_ESCAPE_AS_UTF8).
  2. treat selected text as query and segment (URL_ESCAPE_PERCENT | URL_ESCAPE_AS_UTF8).
  3. treat selected text as segment only (old behavior, URL_ESCAPE_SEGMENT_ONLY | URL_ESCAPE_AS_UTF8).

@Spsp1981
Copy link
Author

Spsp1981 commented Nov 7, 2024

OK, I took my time to read and test and the function is actually working as expected according to that document. That being said, the URL used in that document is garbage, the only way that would ever be usefull in real programming life would be if you're creating a website in a non-english language and your filenames do not adhere to any accepted naming standard whatsoever:

http://misitioweb.org/página de consultas sobre montañas.asp?q=montaña+everest
(Spanish made up page, translates to: webpage for querying about mountains.asp?q=mountain+everest)

becomes:

http://misitioweb.org/p%C3%A1gina%20de%20consultas%20sobre%20monta%C3%B1as.asp?q=montaña+everest

No self-respecting developer will ever do something like that! (Note that the query part was not encoded, that's even worse)

Most of the times I've seen (and used) URLs that need encoding is for website redirection (specially third party). For example, this is shared (cleaned up) URL taken from Facebook:

https://l.facebook.com/l.php?u=https%3A%2F%2Fwww.beinsports.com%2Fen-us%2Fsoccer%2Fuefa-champions-league%2Farticles-video%2F-video-robert-lewandowski-s-brilliant-brace-in-the-champions-league-2024-11-06%3Ffbclid%3D

If I use URL decode, everything's great:

https://l.facebook.com/l.php?u=https://www.beinsports.com/en-us/soccer/uefa-champions-league/articles-video/-video-robert-lewandowski-s-brilliant-brace-in-the-champions-league-2024-11-06?fbclid=

But if I want to reverse it, I can't. Having the pair Encode/Decode URL implies that one function is able to "Undo" whatever the other function did, and that's not the case here.

@zufuliu
Copy link
Owner

zufuliu commented Nov 8, 2024

Looks it's my failure:
https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-urlescapew#remarks

By default, UrlEscape ignores any text following a # or ? character. The URL_ESCAPE_SEGMENT_ONLY flag overrides this behavior by regarding the entire string as the segment.

@Spsp1981
Copy link
Author

Spsp1981 commented Nov 8, 2024

As the function works on selected text, I think it may be easier and more practical to treat the whole selection as the string to encode rather than just an arbitrary portion of it. As per my understanding (I may be wrong), this wouldn't conflict with #315

@zufuliu
Copy link
Owner

zufuliu commented Nov 8, 2024

JavaScript has encodeURI() and encodeURIComponent(), I think we can add menu "URL Component Encode"; for the facebook URL, text after https://l.facebook.com/l.php?u= is a single component.

@zufuliu zufuliu added 🌐i18n Localization/Internationalization ui labels Nov 8, 2024
@zufuliu
Copy link
Owner

zufuliu commented Nov 8, 2024

Commit b623310 added menu "URL Component Encode" (for old behavior), user will need to decide which menu to use (whole URL like JavaScript encodeURI() or only component like JavaScript encodeURIComponent()).

CC @xelsios, @VoilierBleu, @Matteo-Nigro, @maboroshin, @VenusGirl, @tretdm for translation updates, also note that commit a263fdd added "Use &Large Toolbar" menu for matepath.

@zufuliu zufuliu added this to the v24.11 milestone Nov 8, 2024
@zufuliu zufuliu closed this as completed Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💬discussion 🌐i18n Localization/Internationalization ❓question ui
Projects
None yet
Development

No branches or pull requests

3 participants