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

Further improve CJK and encoded URL support #61

Merged
merged 11 commits into from
Aug 29, 2024

Conversation

scarf005
Copy link
Contributor

@scarf005 scarf005 commented Aug 26, 2024

  • added punycode.js to parse punycode encoded path elements from URL constructor
  • handles CJK path for blobs, wiki pages, and external web pages

Copy link
Member

@fregante fregante left a comment

Choose a reason for hiding this comment

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

Thanks! I was thinking about this while working on b5d9e28

Can you check if it fixed it? More test cases are definitely welcome so that regressions are caught. Especially for searches like:

https://github.com/refined-github/shorten-repo-url/issues?q=sort%3Aupdated-desc+is%3Aissue+is%3Aopen+label%3A%22help+wanted%22

index.test.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
@fregante
Copy link
Member

By the way, you don't have to force-push, it makes it difficult to see what changed between reviews

@scarf005
Copy link
Contributor Author

By the way, you don't have to force-push, it makes it difficult to see what changed between reviews

sorry, out of habit. won't do it next time.

@fregante fregante added the bug label Aug 26, 2024
@fregante fregante changed the title fix: decode unicode in URL Further improve CJK support in URLs Aug 26, 2024
scarf005 and others added 2 commits August 26, 2024 23:22
didn't notice safeDecode was only used in isCustomLink
@scarf005 scarf005 requested a review from fregante August 26, 2024 14:27
@fregante
Copy link
Member

fregante commented Aug 26, 2024

This seems to be unfortunately correct, however I'm not a fan of loading that library for such a rare occurrence. However I think we have an alternative:

  1. in applyToLink, pass the label, not the URL (getLinkHref(a) wasn't needed here), so we have access to the user-formatted URL rather than a pre-parsed version.
  2. On line 180, I think we can drop decodeURI altogether
  3. On line 163, we can extract the origin manually (href.split('/')[2]) instead of using parsedUrl.origin

I'll try this

Copy link
Member

@fregante fregante left a comment

Choose a reason for hiding this comment

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

Might be good now

searchParams,
hash,
} = url;
const {search, searchParams} = url;
Copy link
Member

Choose a reason for hiding this comment

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

This part, together with the change in applyToLink, should resolve the problem at the root: shortenRepoUrl() now works directly on what the user sees, not the result of new URL

I'll release this as a breaking version

@fregante fregante merged commit a20489a into refined-github:main Aug 29, 2024
3 checks passed
@fregante fregante changed the title Further improve CJK support in URLs Further improve CJK and encoded URL support Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants