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: filter with special characters #885

Merged
merged 3 commits into from
Sep 24, 2021
Merged

fix: filter with special characters #885

merged 3 commits into from
Sep 24, 2021

Conversation

MoritzRS
Copy link
Contributor

PR Type

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no API changes)
[ ] Build-related changes
[ ] CI-related changes
[ ] Documentation content changes
[ ] Application / infrastructure changes
[ ] Other:

What Is the Current Behavior?

When applying search filter with characters like "&" or "/" leads to false encodet parameters in the rest request.

What Is the New Behavior?

When applying search filter with special characters, parameters are encodet properly.

Does this PR Introduce a Breaking Change?

[ ] Yes
[x] No

Other Information

The change from decodeURI to decodeURIComponent works for the filters, but wasn't tested enough and might lead to unexpected behavior elsewhere.

@dhhyi
Copy link
Collaborator

dhhyi commented Sep 21, 2021

@MoritzRS Following https://stackoverflow.com/a/747700 using decodeURIComponent instead of decodeURI should be exactly what is originally intended, since we are working inside the query param boundary on a specific param. (I learned something today 😅). Thanks for the PR.

But I wonder: Normally, Angular should take care of encoding and decoding the params properly, so why do we have to do it here at all? I suspect there is a wrong encodeURI somewhere that causes it.

@MoritzRS
Copy link
Contributor Author

I also found this suspicious that you have to decode at all. I will look into this and see if I find that encoding part. Thanks for replying

@MoritzRS
Copy link
Contributor Author

The request at https://pwa-ish-demo.test.intershop.com/INTERSHOP/rest/WFS/inSPIRED-inTRONICS-Site/rest;loc=en_US;cur=USD/productfilters?searchTerm=* already returns the encoded string. So "/" is already encoded as "%2F" when angular receives the possible filter options

@dhhyi
Copy link
Collaborator

dhhyi commented Sep 23, 2021

@MoritzRS That means, we just have to decoreURLComponent correctly when we parse the filter values.

If I follow the mapping, it happens here:

...stringToFormParams(facet.link.uri.split('?')[1] || ''),

So if we look at this line in the stringToFormParams:

return { key, value: values.split(separator) };

The decoding can happen with values.split(separator).map(decodeURIComponent).
And then we would not need the decoding in appendFormParamsToHttpParams at all.

Does that sound plausible?

@MoritzRS
Copy link
Contributor Author

Seems good to me and works just as expected. Thanks 😄

@MoritzRS
Copy link
Contributor Author

Worked for the brand filter only but breaks every other Filter. First commit worked for me with all other filters but I'll do some tests before reverting.

@dhhyi
Copy link
Collaborator

dhhyi commented Sep 23, 2021

@MoritzRS No, please don't revert, we only go forward! 😄

As far as I can see, it only doesn't work for prices, because they use range instructions and also have encoded keys, so they also must be decoded and the line should become:

{ key: decodeURIComponent(key), value: values.split(separator).map(decodeURIComponent) }

@shauke shauke added the bug Something isn't working label Sep 24, 2021
@shauke shauke added this to the 1.2 milestone Sep 24, 2021
@MoritzRS
Copy link
Contributor Author

Should work by now. Thanks for your help 😄

I'll do my best to verify changes are working before committing in the future so we don't always have this back and forth over such little changes 😅

@dhhyi
Copy link
Collaborator

dhhyi commented Sep 24, 2021

I'll do my best to verify changes are working before committing in the future so we don't always have this back and forth over such little changes 😅

No worries, that's what these collaboration tools are built for. It just takes a little bit longer 😉👍

@shauke shauke merged commit 5f628d6 into intershop:develop Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants