Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no quote on attrs #10117

Merged
merged 1 commit into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function getScriptInfo(node: DefaultTreeAdapterMap['element']): {
return { src, sourceCodeLocation, isModule, isAsync }
}

const attrValueStartRE = /=[\s\t\n\r]*(["']|.)/
const attrValueStartRE = /=[\s\t\n\r]*(.)/

export function overwriteAttrValue(
s: MagicString,
Expand All @@ -214,7 +214,7 @@ export function overwriteAttrValue(
`[vite:html] internal error, failed to overwrite attribute value`
)
}
const wrapOffset = valueStart[1] ? 1 : 0
const wrapOffset = valueStart[1] === '"' || valueStart[1] === "'" ? 1 : 0
const valueOffset = valueStart.index! + valueStart[0].length - 1
s.overwrite(
sourceCodeLocation.startOffset + valueOffset + wrapOffset,
Expand Down
11 changes: 11 additions & 0 deletions playground/html/__tests__/html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,14 @@ test('importmap', () => {
'An import map is added after module script load was triggered.'
)
})

describe('Valid HTML', () => {
test('valid HTML is parsed', async () => {
await page.goto(viteTestUrl + '/valid.html')
expect(await page.textContent('#no-quotes-on-attr')).toBe(
'No quotes on Attr working'
)

expect(await getColor('#duplicated-attrs')).toBe('green')
})
})
3 changes: 3 additions & 0 deletions playground/html/valid.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
<datalist>
<option value="option-without-closing-tag">
</datalist>

<div id="no-quotes-on-attr">No quotes on Attr</div>
<script type="module" src=/valid.js></script>
3 changes: 3 additions & 0 deletions playground/html/valid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
document.getElementById(
`no-quotes-on-attr`
).innerHTML = `No quotes on Attr working`