[VER-421] fix: Correctly inject body classes when <body>
has no attributes
#1194
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previous regex would inject body classes in the wrong place if the body has no attributes but its child div has class attribute
In that case, the function would inject the classes in the child div classes
With previous regex the following HTML
Would output
With new regex, it outputs
This also fixes a production bug where we found that a
div
with same value forrole
andclass
would see values injected in itsrole
instead of itsclass
(this only happens ifrole
is declared first)With previous regex the following HTML
Would output
This would break
document.querySelector("[role=application]")
call made by our librariesThis commit fixes this observed bug, but this is a side effect as we now ensure that only the
<body>
tag is impactedBut the bug would reappear if someday some of our apps has similar pattern inside of their
body
tags (this is not the case today)