Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Avoid breaking changes - The original path has higher priority #105

Merged

Conversation

SukkaW
Copy link
Contributor

@SukkaW SukkaW commented Jun 6, 2020

This PR superseded #104 (and close #99 again).

In order to prevent Breaking Changes introduced in #100, the changes have been made:

  • Look up original path in ASSET_MANIFEST first, so user-encoded file will be served properly
  • The original path has higher priority, so browser-encoded filename will not be broken.
  • Only when original path is not found in ASSET_MANIFEST, try decode URL then find again.
  • If anything could be found after URL is decoded, mark pathIsEncoded as true.
  • Otherwise, fallback to 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

@SukkaW SukkaW changed the title Avoid breaking changes Avoid breaking changes - The original path has higher priority Jun 6, 2020
'%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',
Copy link
Contributor Author

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.

Comment on lines +91 to +113
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')
}
})
Copy link
Contributor Author

@SukkaW SukkaW Jun 6, 2020

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.

Copy link

@harrishancock harrishancock left a 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!

Copy link
Contributor

@EverlastingBugstopper EverlastingBugstopper left a comment

Choose a reason for hiding this comment

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

Awesome!

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

Successfully merging this pull request may close these issues.

Non ASCII path returned 404
4 participants