]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(parser): properly set initial inXML state based on root ns
authorEvan You <yyx990803@gmail.com>
Tue, 28 Nov 2023 10:37:17 +0000 (18:37 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 28 Nov 2023 10:37:17 +0000 (18:37 +0800)
packages/compiler-core/src/parser.ts
packages/compiler-dom/__tests__/parse.spec.ts

index 4e3c21480a26c63c85a75ff550c2923e468c40ff..46d9c6f094f69ae7a584c6ede7e0f38ad24a8d3a 100644 (file)
@@ -978,6 +978,10 @@ export function baseParse(input: string, options?: ParserOptions): RootNode {
         ? ParseMode.SFC
         : ParseMode.BASE
 
+  tokenizer.inXML =
+    currentOptions.ns === Namespaces.SVG ||
+    currentOptions.ns === Namespaces.MATH_ML
+
   const delimiters = options?.delimiters
   if (delimiters) {
     tokenizer.delimiterOpen = toCharCodes(delimiters[0])
index 62c21f40dbcf8ff06fadfef06399bc9069735c78..23b0970e1b2c169c0d19aa51e0cec529d7ce3708 100644 (file)
@@ -481,5 +481,20 @@ describe('DOM parser', () => {
       expect(elementForieng.ns).toBe(Namespaces.SVG)
       expect(element.ns).toBe(Namespaces.HTML)
     })
+
+    test('correct XML handling with root ns', () => {
+      // when root ns is an XML namespace, there should be no special content
+      // treatment for <script>, <style>, <textarea> etc.
+      const ast = parse('<script><g/><g/></script>', {
+        ...parserOptions,
+        ns: Namespaces.SVG
+      })
+      const elementSvg = ast.children[0] as ElementNode
+      // should parse as nodes instead of text
+      expect(elementSvg.children).toMatchObject([
+        { type: NodeTypes.ELEMENT, tag: 'g' },
+        { type: NodeTypes.ELEMENT, tag: 'g' }
+      ])
+    })
   })
 })