Skip to content

Instantly share code, notes, and snippets.

Created January 10, 2015 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/359099cc3239e56d4101 to your computer and use it in GitHub Desktop.
Save anonymous/359099cc3239e56d4101 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/DOM/CSS.pm b/lib/Mojo/DOM/CSS.pm
index 45d9ee2..c46827f 100644
--- a/lib/Mojo/DOM/CSS.pm
+++ b/lib/Mojo/DOM/CSS.pm
@@ -10,7 +10,8 @@ my $ATTR_RE = qr/
(?:
(\W)? # Operator
=
- (?:"((?:\\"|[^"])*)"|([^\]]+)) # Value
+ (?:"((?:\\"|[^"])*)"|([^\]]+?)) # Value
+ (?:\s+(i))? # Case-insensitive
)?
\]
/x;
@@ -82,7 +83,7 @@ sub _compile {
my $pattern = [[]];
while ($css =~ /$TOKEN_RE/go) {
my ($separator, $element, $pc, $attrs, $combinator)
- = ($1, $2 // '', $3, $6, $11);
+ = ($1, $2 // '', $3, $6, $12);
next unless $separator || $element || $pc || $attrs || $combinator;
@@ -109,7 +110,7 @@ sub _compile {
while $pc =~ /$PSEUDO_CLASS_RE/go;
# Attributes
- push @$selector, ['attr', _name($1), _value($2 // '', $3 // $4)]
+ push @$selector, ['attr', _name($1), _value($2 // '', $3 // $4, $5)]
while $attrs =~ /$ATTR_RE/go;
# Combinator
@@ -279,7 +280,7 @@ sub _unescape {
}
sub _value {
- my ($op, $value) = @_;
+ my ($op, $value, $ci) = @_;
return undef unless defined $value;
$value = quotemeta _unescape($value);
@@ -296,7 +297,7 @@ sub _value {
return qr/$value$/ if $op eq '$';
# Everything else
- return qr/^$value$/;
+ return $ci ? qr/^$value$/i : qr/^$value$/;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment