mirror of https://github.com/vuejs/core.git
fix(parser): properly set initial inXML state based on root ns
This commit is contained in:
parent
ef97e8b07d
commit
47ea285be3
|
@ -978,6 +978,10 @@ export function baseParse(input: string, options?: ParserOptions): RootNode {
|
||||||
? ParseMode.SFC
|
? ParseMode.SFC
|
||||||
: ParseMode.BASE
|
: ParseMode.BASE
|
||||||
|
|
||||||
|
tokenizer.inXML =
|
||||||
|
currentOptions.ns === Namespaces.SVG ||
|
||||||
|
currentOptions.ns === Namespaces.MATH_ML
|
||||||
|
|
||||||
const delimiters = options?.delimiters
|
const delimiters = options?.delimiters
|
||||||
if (delimiters) {
|
if (delimiters) {
|
||||||
tokenizer.delimiterOpen = toCharCodes(delimiters[0])
|
tokenizer.delimiterOpen = toCharCodes(delimiters[0])
|
||||||
|
|
|
@ -481,5 +481,20 @@ describe('DOM parser', () => {
|
||||||
expect(elementForieng.ns).toBe(Namespaces.SVG)
|
expect(elementForieng.ns).toBe(Namespaces.SVG)
|
||||||
expect(element.ns).toBe(Namespaces.HTML)
|
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' }
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue