{"record":{"id":"94a4aa5ef037efef","repo":"swc-project/swc","slug":"missingwhitespacebeforequestioninprocessinginstruc","errorCode":"MissingWhitespaceBeforeQuestionInProcessingInstruction","errorMessage":"Missing whitespace before '?'","messagePattern":"Missing whitespace before '\\?'","errorType":"validation","errorClass":"swc_xml_parser::error::Error","httpStatus":null,"severity":"error","filePath":"crates/swc_xml_parser/src/lexer/mod.rs","lineNumber":1180,"sourceCode":"                    }\n                    // Anything else\n                    // Append the current input character to the processing instruction target and\n                    // stay in the current state.\n                    Some(c) => {\n                        self.validate_input_stream_character(c);\n                        self.set_processing_instruction_token(Some(c), None);\n                    }\n                }\n            }\n            State::PiTargetQuestion => {\n                // Consume the next input character:\n                match self.consume_next_char() {\n                    // U+003E GREATER-THAN SIGN (>)\n                    Some('>') => {\n                        self.reconsume_in_state(State::PiEnd);\n                    }\n                    _ => {\n                        self.errors.push(Error::new(\n                            Span::new(self.cur_pos - BytePos(1), self.input.cur_pos() - BytePos(1)),\n                            ErrorKind::MissingWhitespaceBeforeQuestionInProcessingInstruction,\n                        ));\n                        self.set_processing_instruction_token(None, Some('?'));\n                        self.reconsume_in_state(State::PiData);\n                    }\n                }\n            }\n            State::PiTargetAfter => {\n                // Consume the next input character:\n                match self.consume_next_char() {\n                    // U+0009 CHARACTER TABULATION (Tab)\n                    // U+000A LINE FEED (LF)\n                    // U+0020 SPACE (Space)\n                    // Stay in the current state.\n                    Some(c) if is_whitespace(c) => {\n                        self.skip_next_lf(c);\n                    }","sourceCodeStart":1162,"sourceCodeEnd":1198,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_xml_parser/src/lexer/mod.rs#L1162-L1198","documentation":"XML processing instructions require whitespace between the target and the data (`<?target data?>`). The lexer's PiTargetQuestion state handles a `?` read while scanning the target: if the next character is not `>`, the target runs directly into `?`-prefixed data with no separating whitespace, and `MissingWhitespaceBeforeQuestionInProcessingInstruction` is reported (crates/swc_xml_parser/src/lexer/mod.rs:1180). The `?` is then reconsumed as PI data so lexing continues.","triggerScenarios":"Parsing PIs shaped like `<?target?data?>` or `<?php?echo?>` — any PI where a `?` appears at/after the target without whitespace and is not immediately followed by `>` terminating the PI.","commonSituations":"PHP-style processing instructions pasted into XML/XHTML templates; PIs generated by string concatenation without inserting the mandatory space; stylesheet targets that accidentally contain `?` (e.g. `<?xml-stylesheet?href=...?>`).","solutions":["Insert whitespace between target and data: `<?target data?>`","If there is no data, terminate cleanly as `<?target?>`","Escape or drop stray `?` characters inside the target portion","Emit PIs with a serializer/template helper that always inserts the required space"],"exampleFix":"<!-- before -->\n<?target?data?>\n<!-- after -->\n<?target data?>","handlingStrategy":"validation","validationCode":"// Validate processing instructions before parsing\nfunction assertValidPi(pi: string): void {\n  // <?target data?> — require whitespace or ?> right after the target\n  const m = pi.match(/^<\\?([A-Za-z_:][-\\w.:]*)(\\s[\\s\\S]*?)?\\?>$/);\n  if (!m) throw new Error(`malformed processing instruction: ${pi}`);\n  if (m[2] !== undefined && !/^\\s/.test(m[2])) throw new Error('missing whitespace between PI target and data');\n}","typeGuard":null,"tryCatchPattern":"for err in parser.take_errors() {\n    if matches!(err.kind, ErrorKind::MissingWhitespaceBeforeQuestionInProcessingInstruction) {\n        // lexer recovered by treating ? as PI data; fix the source PI\n    }\n}","preventionTips":["Always write `<?target data?>` with a space, or `<?target?>` with no data","Generate PIs via a helper that enforces the space, not string concatenation","Keep PHP-style tags out of XML templates served to XML parsers"],"tags":["xml","processing-instruction","whitespace","lexer"],"backgroundTag":"xml-wellformedness-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"}