Skip to content

Conversation

@timkraut
Copy link
Contributor

@timkraut timkraut commented Feb 26, 2018

We ran into an issue with the following code:

{
    "key": "value with , somewhere",
}

This results in:

(key: value with , somewhere)

which makes SASS fail.

This PR converts values outside of a function which contain a comma into a string to avoid that.

The new outcome is:

(key: "value with , somewhere")

If the input contains a function, it is not wrapped in strings:
Input:

{
    "key": "hsl(270, 60%, 70%)",
}

Output:

(key: hsl(270, 60%, 70%))

@pmowrer
Copy link
Owner

pmowrer commented Feb 28, 2018

Thanks for the continuing contributions, @timkraut!

This issue is unfortunately not straightforward and has come up before. We actually made this fix and reverted it. The ambiguous handling of strings in SASS is frustrating and I'm not sure what the right solution is, if any. Please see this discussion: #5 (comment)

@timkraut
Copy link
Contributor Author

timkraut commented Mar 1, 2018

I read through the discussions on this topic. Unfortunately, I don't have a general solution which works for everything. I'm not sure if there is even one.

My PR addresses one particular case which should be rather clear, though: If the value contains a comma, it should be always a string. In this case, I guess it's save to wrap them in a string.

test/index.js Outdated
"key": "value with , somewhere",
})).to.eql('(key: "value with , somewhere")')
});
it('can parse nested maps with invalid keys', function() {
Copy link
Owner

Choose a reason for hiding this comment

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

I'm confused why this test shows up in the diff given that it was merged yesterday. Please rebase if you haven't

} else if (value === '') {
return '""'; // Return explicitly an empty string (Sass would otherwise throw an error as the variable is set to nothing)
} else if (_.isString(value) && value.includes(',')) {
return '"' + value + '"'; // Sass throws an error if a value contains a comma and is not treated as a string
Copy link
Owner

Choose a reason for hiding this comment

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

What about something like hsl(0,0,0)? Sass wouldn't throw, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right... I haven't thought about this... this makes it more difficult

Copy link
Owner

Choose a reason for hiding this comment

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

I'm unsure if this is something people use, but it'd be a breaking change. Is there a list of SASS functions we could refer to?

Copy link
Contributor Author

@timkraut timkraut Mar 1, 2018

Choose a reason for hiding this comment

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

I don't think there is one. We would have to create one manually, I guess.
Maybe instead of checking a list of functions, we could just check for (what, ever).

Copy link
Owner

Choose a reason for hiding this comment

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

I think that sounds like a good compromise!

Copy link
Contributor Author

@timkraut timkraut Mar 2, 2018

Choose a reason for hiding this comment

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

I've implemented the discussed changes. I've adapted the initial PR description to reflect the changes.

Copy link
Owner

@pmowrer pmowrer left a comment

Choose a reason for hiding this comment

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

👍

@pmowrer pmowrer merged commit 75e9748 into pmowrer:master Mar 2, 2018
@timkraut timkraut deleted the comma-in-object branch March 5, 2018 12:06
esr360 pushed a commit to One-Nexus/Synergy-Sass-Importer that referenced this pull request Jan 31, 2019
Convert values containing commas inside of an object into strings
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.

2 participants