@@ -334,6 +334,26 @@ impl<'a> Extractor<'a> {
334
334
return ValidationResult :: Restart ;
335
335
}
336
336
337
+ // Only allow parentheses for the shorthand arbitrary custom properties syntax
338
+ if let Some ( index) = utility. find ( b"(" ) {
339
+ let mut skip_parens_check = false ;
340
+ let start_brace_index = utility. find ( b"[" ) ;
341
+ let end_brace_index = utility. find ( b"]" ) ;
342
+
343
+ match ( start_brace_index, end_brace_index) {
344
+ ( Some ( start_brace_index) , Some ( end_brace_index) ) => {
345
+ if start_brace_index < index && end_brace_index > index {
346
+ skip_parens_check = true ;
347
+ }
348
+ }
349
+ _ => { }
350
+ }
351
+
352
+ if !skip_parens_check && !utility[ index + 1 ..] . starts_with ( b"--" ) {
353
+ return ValidationResult :: Restart ;
354
+ }
355
+ }
356
+
337
357
// Pluck out the part that we are interested in.
338
358
let utility = & utility[ offset..( utility. len ( ) - offset_end) ] ;
339
359
@@ -911,9 +931,6 @@ impl<'a> Extractor<'a> {
911
931
fn generate_slices ( & mut self , candidate : & ' a [ u8 ] ) -> ParseAction < ' a > {
912
932
match self . without_surrounding ( ) {
913
933
Bracketing :: None => ParseAction :: SingleCandidate ( candidate) ,
914
- Bracketing :: Included ( sliceable) if sliceable == candidate => {
915
- ParseAction :: SingleCandidate ( candidate)
916
- }
917
934
Bracketing :: Included ( sliceable) | Bracketing :: Wrapped ( sliceable) => {
918
935
if candidate == sliceable {
919
936
ParseAction :: SingleCandidate ( candidate)
@@ -1117,7 +1134,7 @@ mod test {
1117
1134
assert_eq ! ( candidates, vec![ "something" ] ) ;
1118
1135
1119
1136
let candidates = run ( " [feature(slice_as_chunks)]" , false ) ;
1120
- assert_eq ! ( candidates, vec![ "feature( slice_as_chunks) " ] ) ;
1137
+ assert_eq ! ( candidates, vec![ "feature" , " slice_as_chunks"] ) ;
1121
1138
1122
1139
let candidates = run ( "![feature(slice_as_chunks)]" , false ) ;
1123
1140
assert ! ( candidates. is_empty( ) ) ;
@@ -1213,9 +1230,8 @@ mod test {
1213
1230
1214
1231
#[ test]
1215
1232
fn ignores_arbitrary_property_ish_things ( ) {
1216
- // FIXME: () are only valid in an arbitrary
1217
1233
let candidates = run ( " [feature(slice_as_chunks)]" , false ) ;
1218
- assert_eq ! ( candidates, vec![ "feature( slice_as_chunks) " , ] ) ;
1234
+ assert_eq ! ( candidates, vec![ "feature" , " slice_as_chunks", ] ) ;
1219
1235
}
1220
1236
1221
1237
#[ test]
@@ -1637,7 +1653,6 @@ mod test {
1637
1653
1638
1654
#[ test]
1639
1655
fn arbitrary_properties_are_not_picked_up_after_an_escape ( ) {
1640
- _please_trace ( ) ;
1641
1656
let candidates = run (
1642
1657
r#"
1643
1658
<!-- [!code word:group-has-\\[a\\]\\:block] -->
@@ -1648,4 +1663,48 @@ mod test {
1648
1663
1649
1664
assert_eq ! ( candidates, vec![ "!code" , "a" ] ) ;
1650
1665
}
1666
+
1667
+ #[ test]
1668
+ fn test_find_candidates_in_braces_inside_brackets ( ) {
1669
+ let candidates = run (
1670
+ r#"
1671
+ const classes = [wrapper("bg-red-500")]
1672
+ "# ,
1673
+ false ,
1674
+ ) ;
1675
+
1676
+ assert_eq ! (
1677
+ candidates,
1678
+ vec![ "const" , "classes" , "wrapper" , "bg-red-500" ]
1679
+ ) ;
1680
+ }
1681
+
1682
+ #[ test]
1683
+ fn test_is_valid_candidate_string ( ) {
1684
+ assert_eq ! (
1685
+ Extractor :: is_valid_candidate_string( b"foo" ) ,
1686
+ ValidationResult :: Valid
1687
+ ) ;
1688
+ assert_eq ! (
1689
+ Extractor :: is_valid_candidate_string( b"foo-(--color-red-500)" ) ,
1690
+ ValidationResult :: Valid
1691
+ ) ;
1692
+ assert_eq ! (
1693
+ Extractor :: is_valid_candidate_string( b"bg-[url(foo)]" ) ,
1694
+ ValidationResult :: Valid
1695
+ ) ;
1696
+ assert_eq ! (
1697
+ Extractor :: is_valid_candidate_string( b"group-foo/(--bar)" ) ,
1698
+ ValidationResult :: Valid
1699
+ ) ;
1700
+
1701
+ assert_eq ! (
1702
+ Extractor :: is_valid_candidate_string( b"foo(\" bg-red-500\" )" ) ,
1703
+ ValidationResult :: Restart
1704
+ ) ;
1705
+ assert_eq ! (
1706
+ Extractor :: is_valid_candidate_string( b"foo-(" ) ,
1707
+ ValidationResult :: Restart
1708
+ ) ;
1709
+ }
1651
1710
}
0 commit comments