{"record":{"id":"1a54954c625e74b0","repo":"swc-project/swc","slug":"invalid-attribute-matcher-value","errorCode":null,"errorMessage":"Invalid attribute matcher value","messagePattern":"Invalid attribute matcher value","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/swc_css_parser/src/parser/selectors/mod.rs","lineNumber":814,"sourceCode":"where\n    I: ParserInput,\n{\n    fn parse(&mut self) -> PResult<AttributeSelectorValue> {\n        match cur!(self) {\n            tok!(\"ident\") => {\n                let ident = self.parse()?;\n\n                Ok(AttributeSelectorValue::Ident(ident))\n            }\n            tok!(\"string\") => {\n                let string = self.parse()?;\n\n                Ok(AttributeSelectorValue::Str(string))\n            }\n            _ => {\n                let span = self.input.cur_span();\n\n                return Err(Error::new(span, ErrorKind::InvalidAttrSelectorMatcherValue));\n            }\n        }\n    }\n}\n\nimpl<I> Parse<AttributeSelectorModifier> for Parser<I>\nwhere\n    I: ParserInput,\n{\n    fn parse(&mut self) -> PResult<AttributeSelectorModifier> {\n        let span = self.input.cur_span();\n\n        match cur!(self) {\n            tok!(\"ident\") => {\n                let value: Ident = self.parse()?;\n\n                Ok(AttributeSelectorModifier {\n                    span: span!(self, span.lo),","sourceCodeStart":796,"sourceCodeEnd":832,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/selectors/mod.rs#L796-L832","documentation":"An attribute selector value, when a value is required, must be either an identifier or a quoted string. The token at the value position is neither — most commonly an unquoted number ('[data-count=5]'), because CSS tokenizes digits as Number, which is not accepted here; dimensions and percentages are likewise rejected.","triggerScenarios":"'[data-count=5]', '[max=100px]', '[tabindex=1]' — unquoted numeric or dimension values in attribute selectors.","commonSituations":"Numeric HTML attributes (tabindex, aria levels, data-* counters) targeted by hand-written or template-generated CSS; regex-constructed selectors that splice raw numbers without quoting; porting XPath/jQuery habits where unquoted numbers are fine.","solutions":["Quote the value: '[data-count=\"5\"]'","Or make it ident-shaped when semantics allow: '[data-count=\"v5\"]' or a leading letter/underscore","When building selectors programmatically, always JSON-quote interpolated values"],"exampleFix":"/* before */\n[data-count=5] { color: red; }\n/* after */\n[data-count=\"5\"] { color: red; }","handlingStrategy":"validation","validationCode":"// Attribute values must be ident or quoted string\nconst attrValueOk = /^(\"[^\"]*\"|'[^']*'|-?[_A-Za-z][\\w-]*)$/;\nfunction checkAttrValue(v) { return attrValueOk.test(v.trim()); }","typeGuard":"null-ish: use a builder instead","tryCatchPattern":"// JS builder: quote anything not ident-shaped\nconst valuePart = checkAttrValue(v) ? v : JSON.stringify(v);\nconst sel = `[${name}${op}${valuePart}]`;","preventionTips":["Always JSON.stringify interpolated attribute values","Do not port XPath/jQuery selector habits with bare numbers","Add a lint rule for unquoted numeric attribute values"],"tags":["css","selector","attribute-selector","quoting"],"backgroundTag":"css-attribute-selector-syntax-error","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}