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 parsing of minimized css output #2689

Merged
merged 1 commit into from
Dec 4, 2015

Conversation

TimvdLippe
Copy link
Contributor

The problem was the expression [\s;] in the first non-capturing group. This incorrectly consumed the ; from a previous css rule.

image

This check was introduced at 6433f62 for #1389.

Fixes #2483

@samccone
Copy link
Contributor

samccone commented Nov 5, 2015

R: @tjsavage for slotting

@tjsavage
Copy link
Contributor

tjsavage commented Nov 5, 2015

Adding @azakus who has been taking a look

@nazar-pc
Copy link
Contributor

nazar-pc commented Nov 5, 2015

There was somewhat similar fix in 883aa5c, just did PR to this PR to improve regexp a bit: TimvdLippe#1

@TimvdLippe
Copy link
Contributor Author

Yes I have tried that solution, but that fails on detecting incorrect variable names like name--incorrect. It will leave up the name, causing weird CSS to happen. Therefore I decided to explicitly capture more characters in front, in order to circumvent the 'failures'.

You can try this yourself by adding the incorrect variable and inspecting using chrome dev tools when running the unit test. The element should have a CSS rule with warning, indicating invalid CSS is applied to the element.

However, if this CSS weirdness is more desired than capturing everything, your patch seems fine. I will leave that for the core team to decide.

@nazar-pc
Copy link
Contributor

nazar-pc commented Nov 5, 2015

Well, I've tried that and unfortunately both our regexps are not good, they start capturing incorrect CSS property - in your case completely (doesn't harm, incorrect property), in my case partially (might override some custom properties?).
I'll try to find something that will cover all cases.

@TimvdLippe
Copy link
Contributor Author

What I tried (and did work together with my regex) was throwing a SyntaxError upon catching incorrect CSS variable names. However, this is against the CSS spec if I am not mistaken, but at least clearly notifies the user what is going on. It therefore failed this testcase.

To achieve this I changed https://github.com/Polymer/polymer/blob/master/src/lib/css-parse.html#L150 to

.replace(this._rx.customProp, function(match) {
  if (match.trim().indexOf(this.VAR_START) !== 0) {
    throw new SyntaxError("Invalid CSS variable defined '" + match + "'");
  }
  return '';
})

P.S. The variable declaration is ignored by Polymer, as it is unable to find any var(name--incorrect). All in all these regexes are quite tricky to get completely right, if not impossible.

@nazar-pc
Copy link
Contributor

nazar-pc commented Nov 6, 2015

I think throwing exception is a good idea, never seen -- in the middle of any css property.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@googlebot googlebot added cla: no and removed cla: yes labels Nov 6, 2015
@TimvdLippe
Copy link
Contributor Author

I will squash the commits tomorrow to also fix the cla

@nazar-pc
Copy link
Contributor

nazar-pc commented Nov 6, 2015

@googlebot, what is wrong?) I'm OK with that, confirm or whatever word you're expecting

@dfreedm
Copy link
Member

dfreedm commented Nov 6, 2015

googlebot gets confused if the commiter email does not match the author email

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Nov 6, 2015
@TimvdLippe
Copy link
Contributor Author

Commits have been squashed and the PR is again available for review @azakus . If/when this PR is merged, I shall create an issue to discuss the addition of the SyntaxError.

@dfreedm
Copy link
Member

dfreedm commented Nov 6, 2015

LGTM, @sorvell for review

nazar-pc added a commit to nazar-pc/CleverStyle-Framework that referenced this pull request Nov 6, 2015
nazar-pc added a commit to nazar-pc/CleverStyle-Framework that referenced this pull request Nov 13, 2015
@ebidel
Copy link
Contributor

ebidel commented Nov 16, 2015

Ping

@tjsavage tjsavage assigned sorvell and unassigned dfreedm Nov 16, 2015
@rubenstolk
Copy link
Contributor

Any update on this @sorvell?

@TimvdLippe
Copy link
Contributor Author

PR rebased onto current master.

dfreedm added a commit that referenced this pull request Dec 4, 2015
@dfreedm dfreedm merged commit 090e9d6 into Polymer:master Dec 4, 2015
@TimvdLippe
Copy link
Contributor Author

@azakus for some reason the PR did not fail, but when merged into master Travis complained on Safari: https://travis-ci.org/Polymer/polymer/builds/94970278#L1630

I don't have safari myself, but could you confirm/deny the tests break in that browser? For some reason the tests in this PR were not run in safari, as seen at https://travis-ci.org/Polymer/polymer/builds/94621570#L1557

@TimvdLippe TimvdLippe deleted the polybuild-css-parser-fix branch December 4, 2015 23:16
@dfreedm
Copy link
Member

dfreedm commented Dec 5, 2015

Reverting for now, moved into branch JeremybellEU-fix-min-css

@kevinpschaaf
Copy link
Member

@JeremybellEU FYI, since we moved our CI runner to Travis, 3rd-party PR's are only tested against browsers that we can run on the Travis VM (Firefox & Chrome); the full browser matrix is only run on Sauce for pushes to non-forked branches, due to Travis's lack of support for a secured test configuration needed to keep Sauce keys private (something we're hoping to work with them to fix).

@nazar-pc
Copy link
Contributor

nazar-pc commented Dec 5, 2015

@kevinpschaaf, in fact Travis have support for private environmental variables, configs in .travis.yml and more. I have such key for decrypting certificate to create digital signatures on releases in one of my projects.
Here are docs:

@dfreedm
Copy link
Member

dfreedm commented Dec 5, 2015

@nazar-pc Yep, we use encrypted variables for the sauce configuration. https://github.com/Polymer/polymer/blob/master/.travis.yml#L18-L21

@kevinpschaaf
Copy link
Member

@nazar-pc Travis will only decrypt such keys for first-party branches, not for forks, since a malicious forker could echo the decrypted keys to the log by modifying the .travis.yml file to do just that.

From the page you linked:

Please note that encrypted environment variables are not available for pull requests from forks.

When I say "secured test configuration", I mean we'd like the option to be able to specify the .travis.yml file itself in a secured location (e.g. not in the repo, which the contributor can change in their fork, but on the travis website, for example).

@TimvdLippe TimvdLippe restored the polybuild-css-parser-fix branch December 20, 2015 12:25
@TimvdLippe TimvdLippe deleted the polybuild-css-parser-fix branch February 5, 2016 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants