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: Prettify URLs #372

Merged
merged 5 commits into from
Oct 24, 2023
Merged

feat: Prettify URLs #372

merged 5 commits into from
Oct 24, 2023

Conversation

franky47
Copy link
Member

@franky47 franky47 commented Oct 22, 2023

Don't URL-encode safe characters, and fix the array parser logic.

Proposed encoding, compared with built-in solutions:

┌──────┬──────────────────┬────────────────┬────────────────────┐
│ char │ encodeQueryValue │ encodeURI      │ encodeURIComponent │
├──────┼──────────────────┼────────────────┼────────────────────┤
│  !   │   !              │   !            │   !                │
│  "   │          %22     │          %22   │          %22       │
│  #   │          %23     │   #            │          %23       │
│  $   │   $              │   $            │          %24       │
│  %   │          %25     │          %25   │          %25       │
│  &   │          %26     │   &            │          %26       │
│  '   │          %27     │   '            │   '                │
│  (   │   (              │   (            │   (                │
│  )   │   )              │   )            │   )                │
│  *   │   *              │   *            │   *                │
│  +   │          %2B     │   +            │          %2B       │
│  ,   │   ,              │   ,            │          %2C       │
│  -   │   -              │   -            │   -                │
│  .   │   .              │   .            │   .                │
│  /   │   /              │   /            │          %2F       │
│  :   │   :              │   :            │          %3A       │
│  ;   │   ;              │   ;            │          %3B       │
│  <   │          %3C     │          %3C   │          %3C       │
│  =   │   =              │   =            │          %3D       │
│  >   │          %3E     │          %3E   │          %3E       │
│  ?   │   ?              │   ?            │          %3F       │
│  @   │   @              │   @            │          %40       │
│  [   │   [              │          %5B   │          %5B       │
│  \   │   \              │          %5C   │          %5C       │
│  ]   │   ]              │          %5D   │          %5D       │
│  ^   │   ^              │          %5E   │          %5E       │
│  _   │   _              │   _            │   _                │
│  `   │          %60     │          %60   │          %60       │
│  {   │   {              │          %7B   │          %7B       │
│  |   │   |              │          %7C   │          %7C       │
│  }   │   }              │          %7D   │          %7D       │
│  ~   │   ~              │   ~            │   ~                │
└──────┴──────────────────┴────────────────┴────────────────────┘

Explanation:

  • + is encoded as %2B in order not to be confused with a space according to RFC-3986. Equally, spaces will be changed to + (not shown here)
  • % are encoded to avoid being interpreted as incomplete escape sequences
  • # is encoded to avoid being interpreted as the URL hash and breaking the query string
  • & is encoded to avoid being interpreted as a query entry separator
  • ", ' and backtick are encoded to avoid breaking URLs when pasted as-is in editors that detect them and emit an anchor tag (social networks, messaging apps).

Compared to encodeURI, the following characters are un-encoded: [\]^{|}. Brackets are particularly useful to keep "pretty" in order to identify arrays or objects when using the JSON parser.

Closes #355.

Don't URL-encode safe characters, and fix the array parser logic.

Closes #355.
@vercel
Copy link

vercel bot commented Oct 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-usequerystate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2023 3:25pm

@sladjanstojcic
Copy link

When do we think this could go live? I am doing a project with this and literary want to replace it with a diff library due to encoding/ugly URLs lol

@franky47
Copy link
Member Author

Can you give 1.9.0-beta.1 a try and see if the encoding works out for you?

@sladjanstojcic
Copy link

Can you give 1.9.0-beta.1 a try and see if the encoding works out for you?

Will do, later today or tomorrow morning.

@franky47 franky47 merged commit f7ed0b5 into next Oct 24, 2023
6 checks passed
@franky47 franky47 deleted the feat/355-pretty-urls branch October 24, 2023 12:25
@franky47 franky47 mentioned this pull request Oct 24, 2023
@sladjanstojcic
Copy link

@franky47 I tried it and everything works, will use it to finish the project.

@franky47
Copy link
Member Author

@sladjanstojcic Thanks for your feedback, 1.9.0 should be landing soon.

@github-actions
Copy link

🎉 This PR is included in version 1.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a nice-url option that does not encode /, objects and arrays
2 participants