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

fix(dev): properly support slugs with URL-encoded characters #299

Merged
merged 1 commit into from
Apr 12, 2023

Conversation

tmeyer2115
Copy link
Contributor

@tmeyer2115 tmeyer2115 commented Apr 12, 2023

A German partner was running into an issue with local PagesJS development. The slug field values for a number of their locations contained special, German characters. When navigating to an entity page with such a slug, the resultant generate-test-data command would fail. An example slug would be something like:

thüringen/gotha/harjesstraße-5

In serverRenderSlugRoute, we were re-constructing the slug value using an encoded version of the URL. That is, instead of the value being the above, PagesJS computed it to be:

th%C3%BCringen/gotha/harjesstra%C3%9Fe-5

This URL-encoded slug was then passed directly to generate-test-data, which could obviously find no corresponding entity. In this PR, I fixed the re-construction of the slug to ensure that it never includes any URL-encoding. I also had to update the call to sendAppHTML because the name/path of the Virtual Module doesn't include URL-encoding either.

Note that this issue was only present when running the PagesJS dev server. Builds worked just fine.

J=SLAP-2676
TEST=manual

Verified that I could navigate to a page with a German character in the slug. Verified that I could navigate to a page with no special characters in the slug. Verified that the produciton build still worked as expected.

A German partner was running into an issue with local PagesJS
development. The slug field values for a number of their locations
contained special, German characters. When navigating to an entity
page with such a slug, the resultant `generate-test-data` command would
fail. An example slug would be something like:

thüringen/gotha/harjesstraße-5

In `serverRenderSlugRoute`, we were re-constructing the slug value using
an encoded version of the URL. That is, instead of the value being the
above, PagesJS computed it to be:

th%C3%BCringen/gotha/harjesstra%C3%9Fe-5

This URL-encoded slug was then passed directly to `generate-test-data`,
which could obviously find no corresponding entity. In this PR, I fixed
the re-construction of the slug to ensure that it never includes any
URL-encoding. I also had to update the call to `sendAppHTML` because the
name/path of the Virtual Module shouldn't include URL-encoding either.

Note that this issue was only present when running the PagesJS dev server.
Builds worked just fine.

J=SLAP-2676
TEST=manual

Verified that I could navigate to a page with a German character in the slug.
Verified that I could navigate to a page with no special characters in the slug.
Verified that the produciton build still worked as expected.
@tmeyer2115 tmeyer2115 requested a review from a team as a code owner April 12, 2023 18:53
@tmeyer2115 tmeyer2115 requested a review from oshi97 April 12, 2023 19:11
@@ -69,7 +69,7 @@ export const serverRenderSlugRoute =
locale,
document,
});
sendAppHTML(res, templateModuleInternal, props, vite, url.pathname);
sendAppHTML(res, templateModuleInternal, props, vite, `/${slug}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the sendStaticPage call (line 35) also need to be updated to pass the decoded slug instead of url.pathname?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. I was able to get a static page (with German characters in the path) to load just fine without updating the usage on line 35.

@tmeyer2115 tmeyer2115 requested a review from nmanu1 April 12, 2023 19:36
@tmeyer2115 tmeyer2115 merged commit 759c500 into main Apr 12, 2023
@tmeyer2115 tmeyer2115 deleted the dev/decode-url branch April 12, 2023 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants