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 breaking preprocessors' directives when parsing attributes #171

Merged
merged 3 commits into from Jan 25, 2021
Merged

Fix breaking preprocessors' directives when parsing attributes #171

merged 3 commits into from Jan 25, 2021

Conversation

yeegor
Copy link
Contributor

@yeegor yeegor commented Jan 13, 2021

Overview

The issue described above has been found during the development of the create-scandipwa-app.

Motivation

See the following code example. It is located in a PHP file and is valid: the corresponding function is called when the file is parsed. This has been tested using the Magento 2 framework, nonetheless, it should be possible to recreate this without the framework.

<html lang="<?= $this->getLocaleCode() ?>">

The code fragment above, when parsed back and forth, is expected to remain the same. But in fact, it turns into the following code.

<html lang="&lt;?= $this->getLocaleCode() ?>">

Context

The used version is 0.4.0
The parsing process has been invoked as follows:

const xmldom = require('xmldom');

const domParser = new xmldom.DOMParser();
const xmlSerializer = new xmldom.XMLSerializer();

const templateFile = ...

const parseToDOM = (code) => domParser.parseFromString(code, 'text/html');
const parseToString = (dom) => xmlSerializer.serializeToString(dom);

// This result is broken, as described above
const result = parseToString(parseToDOM(templateFile));

Description

This PR removes < from mandatory-to-replace token list for attribute parsing process.

@karfau
Copy link
Member

karfau commented Jan 14, 2021

I thing we have multiple related issues with entities and roundtrips and this looks like a very valid (but of course breaking) fix for this specific subset of situations described.

Can you run the tests and tell jest to update the snapshots and also adopt any other failing test? Thx.

@karfau
Copy link
Member

karfau commented Jan 19, 2021

The only thing that might be concerning is that with this change the following:

<doc a1="&quot;&lt;&amp;&gt;&apos;"></doc>

will be serialized to

<doc a1="&quot;<&amp;>'"/>

(which is consistent with the already existing behavior for > and ')

@brodybits what do you think?

@karfau karfau requested a review from brodybits January 19, 2021 03:16
@brodybits
Copy link
Member

I wonder if we should just keep the quoted attribute value unchanged.

@karfau
Copy link
Member

karfau commented Jan 19, 2021

I wonder if we should just keep the quoted attribute value unchanged.

I think we should be able to add this as an option to Node.toString/Document.toString() but it would not be something that is part of the standard. And maybe this can rather happen in a different PR?

@karfau karfau added this to the 0.5.0 milestone Jan 21, 2021
@brodybits
Copy link
Member

No more objections on my part. Thanks.

This was referenced Mar 13, 2021
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.

None yet

3 participants