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

Don't treat [ as a part of an attribute name in SCSS #839

Merged
merged 1 commit into from Dec 21, 2017

Conversation

hibariya
Copy link
Contributor

@hibariya hibariya commented Dec 20, 2017

Hello, I've been trying to fix #805.

Apparently, the lexers treat &[href^="mailto:"] as an attribute due to : symbol of mailto:. To fix that, I had them not treat [ as a part of an attribute name.

The issue can be reploduced with the following example.
http://rouge.jneen.net/pastes/7G2N

a {
  &[href^="mailto:"] {
    white-space: nowrap;
  }
}

The part of the debug output of above example is:

lexer: scss
stack: [:root]
stream: "\n  &[href^=\"mailto:\""
  trying #<Rule /\s+/>
    got "\n  "
    yielding Text, "\n  "
lexer: scss
stack: [:root]
stream: "&[href^=\"mailto:\"] {"
  trying #<Rule /\s+/>
  trying #<Rule /\/\/.*?$/>
  trying #<Rule /\/[*].*?[*]\//m>
  trying #<Rule /@import\b/>
  entering mixin content_common
  trying #<Rule /@for\b/>
  trying #<Rule /@(debug|warn|if|each|while|else|return|media)/>
  trying #<Rule /(@mixin)(\s+)((?-mix:[\w-]+))/>
  trying #<Rule /(@function)(\s+)((?-mix:[\w-]+))/>
  trying #<Rule /@extend\b/>
  trying #<Rule /(@include)(\s+)((?-mix:[\w-]+))/>
  trying #<Rule /@(?-mix:[\w-]+)/>
  trying #<Rule /([$](?-mix:[\w-]+))([ \t]*)(:)/>
  exiting  mixin content_common
  trying #<Rule /(?=[^;{}][;}])/>
  trying #<Rule /(?=[^;{}:]+:[^a-z])/>
    got ""
    pushing :attribute

The patch of this Pull Request changes it as following:

$ diff -u debug-scss{,-after}.txt 
--- debug-scss.txt      2017-12-20 12:26:42.903885511 +0900
+++ debug-scss-after.txt        2017-12-20 12:39:44.493408945 +0900
@@ -22,7 +22,7 @@
   trying #<Rule /([$](?-mix:[\w-]+))([ \t]*)(:)/>
   exiting  mixin content_common
   trying #<Rule /(?=[^;{}][;}])/>
-  trying #<Rule /(?=[^;{}:]+:[^a-z])/>
+  trying #<Rule /(?=[^;{}:\[]+:[^a-z])/>
+  trying #<Rule //>
     got ""
-    pushing :attribute
-
+    pushing :selector

@gfx
Copy link
Member

gfx commented Dec 21, 2017

Thanks!

@gfx gfx merged commit 5d039a9 into rouge-ruby:master Dec 21, 2017
@gfx gfx added the bugfix-request A request for a bugfix to be developed. label Dec 21, 2017
@hibariya hibariya deleted the scss branch December 21, 2017 04:21
@gfx gfx changed the title Don't treat [ as a part of an attribute name Don't treat [ as a part of an attribute name in SCSS Dec 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix-request A request for a bugfix to be developed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SCSS breaks on &[attr^="value"] selector
2 participants