Skip to content

Commit 4fd2438

Browse files
committedSep 11, 2024··
fix(nuxt): use case-insensitive regexp for <script> blocks

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed
 

Diff for: ‎packages/nuxt/src/components/islandsTransform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface ComponentChunkOptions {
2424
buildDir: string
2525
}
2626

27-
const SCRIPT_RE = /<script[^>]*>/g
27+
const SCRIPT_RE = /<script[^>]*>/gi
2828
const HAS_SLOT_OR_CLIENT_RE = /<slot[^>]*>|nuxt-client/
2929
const TEMPLATE_RE = /<template>([\s\S]*)<\/template>/
3030
const NUXTCLIENT_ATTR_RE = /\s:?nuxt-client(="[^"]*")?/g

Diff for: ‎packages/vite/src/plugins/composable-keys.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptio
4343
},
4444
transform (code, id) {
4545
if (!KEYED_FUNCTIONS_RE.test(code)) { return }
46-
const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\s\S]*?(?=<\/script>)/) || { index: 0, 0: code }
46+
const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\s\S]*?(?=<\/script>)/i) || { index: 0, 0: code }
4747
const s = new MagicString(code)
4848
// https://github.com/unjs/unplugin/issues/90
4949
let imports: Set<string> | undefined

Diff for: ‎test/basic.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ describe('nuxt composables', () => {
697697
expect(id1).toBeTruthy()
698698
const matches = [
699699
html.match(/<script[^>]*>\(\(\)=>\{console.log\(window\)\}\)\(\)<\/script>/),
700-
html.match(new RegExp(`<script[^>]*>document.querySelectorAll\\('\\[data-prehydrate-id\\*=":${id1}:"]'\\).forEach\\(o=>{console.log\\(o.outerHTML\\)}\\)</script>`)),
701-
html.match(new RegExp(`<script[^>]*>document.querySelectorAll\\('\\[data-prehydrate-id\\*=":${id2}:"]'\\).forEach\\(o=>{console.log\\("other",o.outerHTML\\)}\\)</script>`)),
700+
html.match(new RegExp(`<script[^>]*>document.querySelectorAll\\('\\[data-prehydrate-id\\*=":${id1}:"]'\\).forEach\\(o=>{console.log\\(o.outerHTML\\)}\\)</script>`, 'i')),
701+
html.match(new RegExp(`<script[^>]*>document.querySelectorAll\\('\\[data-prehydrate-id\\*=":${id2}:"]'\\).forEach\\(o=>{console.log\\("other",o.outerHTML\\)}\\)</script>`, 'i')),
702702
]
703703

704704
// This tests we inject all scripts correctly, and only have one occurrence of multiple calls of a composable

0 commit comments

Comments
 (0)
Please sign in to comment.