serve-handler icon indicating copy to clipboard operation
serve-handler copied to clipboard

Disable encoding on url segments

Open rjimenezda opened this issue 6 years ago • 3 comments

I was trying to rewrite all urls that looked like a/b/:path+ to c/d/:path, so in practice:

a/b/file => c/d/file a/b/dir/dir/dir/file => c/d/dir/dir/file

However, it didn't work. After some digging I found that path-to-regexp was encoding the slashes in the matched url segment.

However, you can pass a custom encoder, so I've added an option on rewrite objects to use an identity function (value => value), so no character gets encoded in the URL. I've named it raw but I'm open to suggestions.

There's a minor detail, you also have to provide the regex for the destintation, because by default they disallow certain characters there as well. I've added an example to the README mentioning this too. Also, a small test case.

rjimenezda avatar Apr 03 '19 10:04 rjimenezda

Codecov Report

Merging #85 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #85   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines         324    324           
=====================================
  Hits          324    324
Impacted Files Coverage Δ
src/index.js 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9101d15...1751eaf. Read the comment docs.

codecov[bot] avatar Apr 03 '19 10:04 codecov[bot]

I wonder what happened to this PR. Seems still valid to me.

a10nik avatar Mar 16 '24 07:03 a10nik