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

🐛 Fixed a replace bug that insert match string in replacement value #1261

Merged
merged 2 commits into from
May 19, 2023

Conversation

ninadbstack
Copy link
Contributor

@ninadbstack ninadbstack commented May 19, 2023

We have a js bug in replace. [ bug for us, its a functionality of replace ]By default js replace function considers everything as regex replace. so as per docs
if we do

"dog cats".replace('dog', '$&cats') => 'dogcats cats' 

reason being $& inserts the match string in the place => in "dog cats" we have match dog which we want to replace with &$cats => replace with dogcats => final output dogcats cats.
The reason it was breaking because we do

docElement.outerHTML.replace('</html>', `${innerHTML}</html>`);

and innerHTML of client dom contains $& in many urls [ and so it was getting replaced with ]

So we are using replacer function that does not trigger this inserts

@ninadbstack ninadbstack added the 🐛 bug Something isn't working label May 19, 2023
@ninadbstack ninadbstack changed the title Fixed replace bug that insert match in return val Fixed replace bug that insert match string in replacement value May 19, 2023
@ninadbstack ninadbstack changed the title Fixed replace bug that insert match string in replacement value Fixed a replace bug that insert match string in replacement value May 19, 2023
integrity sha512-bWTlaXUy/rq0BBtYShc/jArYfBPjEV95euvZ8JVtO43oQExEN/WquoqpufFjNu4kSpi5cy5kMbNvzztWDfv1Jg==
version "1.0.30001488"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001488.tgz"
integrity sha512-NORIQuuL4xGpIy6iCCQGN4iFjlBXtfKWIenlUuyZJumLRIindLb7wXM+GO8erEhb7vXfcnf4BAg2PrSDN5TNLQ==
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we changing this? Lets not commit this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its printing warning in tests + its only dependency of @babel/preset-env which is a dev-dependency of cli [ so safe to upgrade ]

@samarsault samarsault changed the title Fixed a replace bug that insert match string in replacement value 🐛 Fixed a replace bug that insert match string in replacement value May 19, 2023
Copy link
Contributor

@samarsault samarsault left a comment

Choose a reason for hiding this comment

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

Lgtm

@ninadbstack ninadbstack merged commit 8625351 into master May 19, 2023
32 checks passed
@ninadbstack ninadbstack deleted the PER-2109-fix-replace-bug branch May 19, 2023 13:19
shahidk8 pushed a commit that referenced this pull request Jun 29, 2023
…1261)

* Fixed replace bug that insert match in return val

* Updated test to use withExample
samarsault pushed a commit that referenced this pull request Jun 29, 2023
…1261)

* Fixed replace bug that insert match in return val

* Updated test to use withExample
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.

None yet

2 participants