Skip to content

util: Adds CRLF awareness to quote() #1817

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

Merged
merged 1 commit into from
Dec 31, 2015
Merged

util: Adds CRLF awareness to quote() #1817

merged 1 commit into from
Dec 31, 2015

Conversation

am11
Copy link
Contributor

@am11 am11 commented Dec 30, 2015

Input:

@import url("a
b");

Output on Windows:

"@import url(\"a\r\a b\");"

Output on Unix (alinged with Ruby Sass, hence the expected output):

"@import url(\"a\a b\");"

See: #1096 (comment)
for details.

Sepc: sass/sass-spec#664.

@am11
Copy link
Contributor Author

am11 commented Dec 30, 2015

//cc @xzyfer =)

@@ -488,6 +488,12 @@ namespace Sass {

int cp = utf8::next(it, end);

// in case of \r, check if the next in sequence
// is \n and then advance the iterator.
if (cp == '\r' && it < end && utf8::peek_next(it, end) == '\n') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking through the rest of this file it looks like we generally treat \r as a noop. I think you can drop the peek here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great! Fixed by fb1fcd7.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xzyfer, seems like in some cases, we do need to push_back() the carriage return to quoted string: https://travis-ci.org/sass/libsass/jobs/99452071#L1108.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second though, \r is a legal character in Unix and Windows. Now I wonder if Ruby Sass is doing the right thing in first place. 💡

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If CSS3 import only accepts network paths, then \\r is legal string of length 2. :)
I have reverted it back to this original code. Now it aligns with Ruby both on Windows and OSX. CI seems to be happy too. 🌴

@xzyfer
Copy link
Contributor

xzyfer commented Dec 30, 2015

Nice find @am11

@xzyfer
Copy link
Contributor

xzyfer commented Dec 30, 2015

I wonder how we can test this since the spec for #1096 includes this test case and passes on Windows.

@am11
Copy link
Contributor Author

am11 commented Dec 30, 2015

Good point. Since we don't have .gitattributes in sass-spec (which usually enforces the repo-wide linefeed rules), we can probably save https://github.com/sass/sass-spec/blob/65d2f5f/spec/libsass-closed-issues/issue_1096/input.scss in notepad (with CRLF ending), then run it once without this commit to make the error visible on AppVeyor.

@xzyfer
Copy link
Contributor

xzyfer commented Dec 30, 2015

Sounds unreliable. Especially give that we periodically regenerate all the specs (usually on osx or linux).

am11 added a commit to am11/sass-spec that referenced this pull request Dec 30, 2015
@am11
Copy link
Contributor Author

am11 commented Dec 30, 2015

@xzyfer, if you commit from Linux and OSX, it will not affect CRLF endings. I have just committed sass/sass-spec#664 from OSX.

Input:

```scss
@import url("a
b");
```

Output on Windows:

```
"@import url(\"a\r\a b\");"
```

Output on Unix (alinged with Ruby Sass, hence the expected output):

```
"@import url(\"a\a b\");"
```

See: sass#1096 (comment)
for details.
am11 added a commit to am11/sass-spec that referenced this pull request Dec 31, 2015
xzyfer added a commit that referenced this pull request Dec 31, 2015
Adds CRLF awareness to quote()
@xzyfer xzyfer merged commit 50ebca0 into sass:master Dec 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants