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

Prevent TypeError due to undefined property when parsing styles #69

Closed
wants to merge 1 commit into from

Conversation

mdholloway
Copy link
Contributor

Fixes #68.

@@ -17,7 +17,10 @@ function parseStyles(s) {
parser.addListener("property", function(e) {
if (e.invalid) return; // Skip errors
result[e.property.text] = e.value.text;
if (e.important) result.important[e.property.text] = e.important;
if (e.important) {
result.important = {};
Copy link

Choose a reason for hiding this comment

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

Shouldn't this be:

result.important = result.important || {};

to avoid rewriting the object in case it exists already?

@@ -17,7 +17,10 @@ function parseStyles(s) {
parser.addListener("property", function(e) {
if (e.invalid) return; // Skip errors
result[e.property.text] = e.value.text;
if (e.important) result.important[e.property.text] = e.important;
if (e.important) {
result.important = result.important || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing this check every time, result is defined above. Why not do var result = { important: {} };?

Also, naive question, is there a chance e.property.text === 'important'? In which case, L19 may be problematic.

@cscott
Copy link
Collaborator

cscott commented Jan 26, 2016

Could you add a test case for this as well?

@mdholloway
Copy link
Contributor Author

I updated this to incorporate the suggestion from @arlolra and to add a test in /test/domino.js that fails without and passes with the change. (@cscott, I may have misunderstood, were you asking in two places for one test, or two different tests?)

@arlolra, going to your other question, I don't think there's a risk of "important" being used as a CSS property separate from its use as a priority rule...

@d00rman
Copy link

d00rman commented Jan 26, 2016

This is causing quite some exceptions in prod for the Mobile Content Service, so we'd appreciate a quick release. @mdholloway could you also bump the patch version of the pkg so that we can deploy it soon?

@cscott
Copy link
Collaborator

cscott commented Jan 27, 2016 via email

@d00rman
Copy link

d00rman commented Jan 27, 2016

@cscott can we get a timeline for the next release / version bump?

@cscott
Copy link
Collaborator

cscott commented Jan 27, 2016 via email

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

4 participants