-
Notifications
You must be signed in to change notification settings - Fork 48
Avoid breaking changes - The original path has higher priority #105
Avoid breaking changes - The original path has higher priority #105
Conversation
'%not-really-percent-encoded.123HASHBROWN.html': 'browser percent encoded', | ||
'%2F.123HASHBROWN.html': 'user percent encoded', | ||
'你好.123HASHBROWN.html': 'I shouldnt be served', | ||
'%E4%BD%A0%E5%A5%BD.123HASHBROWN.html': 'Im important', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%E4%BD%A0%E5%A5%BD
is URL encoded 你好
.
After this PR, only %E4%BD%A0%E5%A5%BD.html
will be served even when /你好.html
is requested.
test('getAssetFromKV supports browser percent encoded URLs', async t => { | ||
mockGlobal() | ||
const event = getEvent(new Request('https://example.com/%not-really-percent-encoded.html')) | ||
const res = await getAssetFromKV(event) | ||
|
||
if (res) { | ||
t.is(await res.text(), 'browser percent encoded') | ||
} else { | ||
t.fail('Response was undefined') | ||
} | ||
}) | ||
|
||
test('getAssetFromKV supports user percent encoded URLs', async t => { | ||
mockGlobal() | ||
const event = getEvent(new Request('https://blah.com/%2F.html')) | ||
const res = await getAssetFromKV(event) | ||
|
||
if (res) { | ||
t.is(await res.text(), 'user percent encoded') | ||
} else { | ||
t.fail('Response was undefined') | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those test cases are introduced in #104. They are included in this PR as well to show nothing will be broken after this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me; thank you @SukkaW!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
This PR superseded #104 (and close #99 again).
In order to prevent Breaking Changes introduced in #100, the changes have been made:
ASSET_MANIFEST
first, so user-encoded file will be served properlyASSET_MANIFEST
, try decode URL then find again.pathIsEncoded
as true.mapRequestToAsset
method.The test cases added in #104 is also included in this PR as well, to show the Breaking Change has been avoided.
cc @EverlastingBugstopper @harrishancock