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(js-regex): 🐛 Fix Regex Pattern in addScripts Method #59

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gtko
Copy link

@gtko gtko commented Aug 13, 2024

Updated the regular expression in the addScripts method from /<script.</script>/ to /<script([^])</script>/. This change ensures that the script tags are correctly identified, even if they span multiple lines or contain various attributes, improving the robustness of the script injection process.

Updated the regular expression in the addScripts method from /<script.*<\/script>/ to /<script([^]*)<\/script>/. This change ensures that the script tags are correctly identified, even if they span multiple lines or contain various attributes, improving the robustness of the script injection process.
return;
}

data.scripts.forEach(script => {
const scriptRegex = /<script.*<\/script>/;
const scriptRegex = /<script([^]*)<\/script>/;
Copy link
Member

Choose a reason for hiding this comment

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

Could you please explain why a capture group would be necessary and why a negated empty set ([^]*) is better than .*? Thanks :)

Copy link
Author

Choose a reason for hiding this comment

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

The capture group is indeed not necessary in this context. However, using a negated set like [^]* has the advantage of matching multi-line scripts. This allows us to send non-minified JavaScript code as a string across multiple lines. The negated set captures everything until it finds a specific character (if defined), which is beneficial when working with multi-line code or text.

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.

2 participants