fix(compiler): Addressed infinite loop in compiler (#3992)

close #3987
This commit is contained in:
Austin Keener
2021-07-15 14:57:47 -04:00
committed by GitHub
parent 7013e8f578
commit e00aa56658
3 changed files with 90 additions and 4 deletions

View File

@@ -35,3 +35,29 @@ exports[`compiler: codeframe multi-line highlights 1`] = `
4 | \\">
| ^"
`;
exports[`compiler: codeframe newline sequences - unix 1`] = `
"8 | <input name=\\"email\\" type=\\"text\\"/>
9 | </div>
10 | <div id=\\"hook\\">
| ^^^^^^^^^^^^^^^
11 | <label for=\\"password\\">Password</label>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12 | <input name=\\"password\\" type=\\"password\\"/>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13 | </div>
| ^^^^^^^^^^^^"
`;
exports[`compiler: codeframe newline sequences - windows 1`] = `
"8 | <input name=\\"email\\" type=\\"text\\"/>
9 | </div>
10 | <div id=\\"hook\\">
| ^^^^^^^^^^^^^^^
11 | <label for=\\"password\\">Password</label>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12 | <input name=\\"password\\" type=\\"password\\"/>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13 | </div>
| ^^^^^^^^^^^^"
`;

View File

@@ -43,4 +43,49 @@ attr
const attrEnd = source.indexOf(`">`) + 1
expect(generateCodeFrame(source, attrStart, attrEnd)).toMatchSnapshot()
})
{
const source = `
<template>
<div>
<h1>Sign In</h1>
<form>
<div>
<label for="email">Email</label>
<input name="email" type="text"/>
</div>
<div id="hook">
<label for="password">Password</label>
<input name="password" type="password"/>
</div>
</form>
</div>
</template>
`
const startToken = '<div id="hook">'
const endToken = '</div>'
// Explicitly ensure the line-ending for the platform instead of assuming
// the newline sequences used in the source above.
const unixNewlineSource = source.replace(/\r\n/g, '\n')
const windowsNewLineSource = unixNewlineSource.replace(/\n/g, '\r\n')
test('newline sequences - windows', () => {
const keyStart = windowsNewLineSource.indexOf(startToken)
const keyEnd =
windowsNewLineSource.indexOf(endToken, keyStart) + endToken.length
expect(
generateCodeFrame(windowsNewLineSource, keyStart, keyEnd)
).toMatchSnapshot()
})
test('newline sequences - unix', () => {
const keyStart = unixNewlineSource.indexOf(startToken)
const keyEnd =
unixNewlineSource.indexOf(endToken, keyStart) + endToken.length
expect(
generateCodeFrame(unixNewlineSource, keyStart, keyEnd)
).toMatchSnapshot()
})
}
})