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(compiler): fix double escaping of ssrNode attribute values (fix #7223) #7224

Merged

Conversation

felixbuenemann
Copy link
Contributor

This fixes a double escaping of attribute values in the SSR optimizing
compiler, because literal attribute values get escaped early during the
call to addAttr inside processAttrs before it is known, if this
attribute will be serialized to an _ssrNode string template.

Later on the _ssrNode string template gets escaped again to preserve
whitespace and this causes double escaping of the whitespace inside the
attribute value.

This approach fixes the problem by undoing the escaping by parsing the
attribute value JSON in genAttrSegment, which is the easiest fix to
the problem, but probably not the best.

This fixes #7223 at least for the cases where I encountered the problem.

See #7223 for an in-depth description of the problem and a test-case.

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

I would love to add a breaking test, that shows that the fix is working, but I'm not sure were to add it with the large test suite, so some advise on that would be appreciated.

This fixes a double escaping of attribute values in the SSR optimizing
compiler by unescaping the value in `genAttrSegment` because literal
attribute values get escaped early during `processAttrs` before it is
known, if this attribute will be optimized to an _ssrNode string template,
which is escaped as well, causing the double escape.

fix vuejs#7223
@felixbuenemann felixbuenemann changed the title fix(#7223): fix double escaping of ssrNode attribute values fix(compiler): fix double escaping of ssrNode attribute values (fix #7223) Dec 12, 2017
@yyx990803 yyx990803 merged commit 73a89bf into vuejs:dev Dec 12, 2017
@yyx990803
Copy link
Member

Thanks and good catch!

@felixbuenemann felixbuenemann deleted the fix-ssr-attribute-double-escaping branch December 12, 2017 22:08
@felixbuenemann
Copy link
Contributor Author

Thanks for taking care of the missing test in 86e4d75.

lovelope pushed a commit to lovelope/vue that referenced this pull request Feb 1, 2018
This fixes a double escaping of attribute values in the SSR optimizing
compiler by unescaping the value in `genAttrSegment` because literal
attribute values get escaped early during `processAttrs` before it is
known, if this attribute will be optimized to an _ssrNode string template,
which is escaped as well, causing the double escape.

fix vuejs#7223
f2009 pushed a commit to f2009/vue that referenced this pull request Jan 25, 2019
This fixes a double escaping of attribute values in the SSR optimizing
compiler by unescaping the value in `genAttrSegment` because literal
attribute values get escaped early during `processAttrs` before it is
known, if this attribute will be optimized to an _ssrNode string template,
which is escaped as well, causing the double escape.

fix vuejs#7223
aJean pushed a commit to aJean/vue that referenced this pull request Aug 19, 2020
This fixes a double escaping of attribute values in the SSR optimizing
compiler by unescaping the value in `genAttrSegment` because literal
attribute values get escaped early during `processAttrs` before it is
known, if this attribute will be optimized to an _ssrNode string template,
which is escaped as well, causing the double escape.

fix vuejs#7223
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.

vue-template-compiler double-escaping newlines in _ssrNode text string templates
2 participants