Unverified Commit d044c554 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

ci: fix javascript-urls test to account for React 18 (#88249)

This was caught by our React 18 tests which only run on `canary`. There
was a console error about breaking `javascript:` urls in an upcoming
React release but it didn't actually block them.
parent d99021e9
...@@ -7,6 +7,8 @@ import { ...@@ -7,6 +7,8 @@ import {
} from 'next-test-utils' } from 'next-test-utils'
import type { Page, Request } from 'playwright' import type { Page, Request } from 'playwright'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('javascript-urls', () => { describe('javascript-urls', () => {
const { next, isNextDev } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: __dirname, files: __dirname,
...@@ -247,6 +249,8 @@ describe('javascript-urls', () => { ...@@ -247,6 +249,8 @@ describe('javascript-urls', () => {
expect(safePageUrl).toContain('/app/safe') expect(safePageUrl).toContain('/app/safe')
}) })
// React 18 did not block JavaScript URLs, it was just a console error.
if (!isReact18) {
it('should prevent javascript URLs in pages router Link component', async () => { it('should prevent javascript URLs in pages router Link component', async () => {
const { beforePageLoad, getNavigationRequests } = const { beforePageLoad, getNavigationRequests } =
createNavigationInterceptor() createNavigationInterceptor()
...@@ -259,7 +263,11 @@ describe('javascript-urls', () => { ...@@ -259,7 +263,11 @@ describe('javascript-urls', () => {
await browser.elementByCss('a').click() await browser.elementByCss('a').click()
await expectJavascriptUrlBlocked(browser, initialUrl, getNavigationRequests) await expectJavascriptUrlBlocked(
browser,
initialUrl,
getNavigationRequests
)
if (isNextDev) { if (isNextDev) {
await waitForRedbox(browser) await waitForRedbox(browser)
...@@ -281,6 +289,7 @@ describe('javascript-urls', () => { ...@@ -281,6 +289,7 @@ describe('javascript-urls', () => {
const safePageUrl = await browser.url() const safePageUrl = await browser.url()
expect(safePageUrl).toContain('/pages/safe') expect(safePageUrl).toContain('/pages/safe')
}) })
}
it('should prevent javascript URLs in pages router Link as prop', async () => { it('should prevent javascript URLs in pages router Link as prop', async () => {
const { beforePageLoad, getNavigationRequests } = const { beforePageLoad, getNavigationRequests } =
......
...@@ -4,8 +4,7 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url' ...@@ -4,8 +4,7 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url'
export default function Page() { export default function Page() {
return ( return (
<html> <div>
<body>
<main> <main>
<p> <p>
Clicking this link should result in an error where React blocks a Clicking this link should result in an error where React blocks a
...@@ -18,7 +17,6 @@ export default function Page() { ...@@ -18,7 +17,6 @@ export default function Page() {
<footer> <footer>
<Link href="/pages/safe">Safe Page</Link> <Link href="/pages/safe">Safe Page</Link>
</footer> </footer>
</body> </div>
</html>
) )
} }
...@@ -4,8 +4,7 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url' ...@@ -4,8 +4,7 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url'
export default function Page() { export default function Page() {
return ( return (
<html> <div>
<body>
<main> <main>
<p> <p>
Clicking this link should result in an error where React blocks a Clicking this link should result in an error where React blocks a
...@@ -18,7 +17,6 @@ export default function Page() { ...@@ -18,7 +17,6 @@ export default function Page() {
<footer> <footer>
<Link href="/pages/safe">Safe Page</Link> <Link href="/pages/safe">Safe Page</Link>
</footer> </footer>
</body> </div>
</html>
) )
} }
...@@ -6,12 +6,11 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url' ...@@ -6,12 +6,11 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url'
export default function Page() { export default function Page() {
const router = useRouter() const router = useRouter()
return ( return (
<html> <div>
<body>
<main> <main>
<p> <p>
Clicking this button should result in an error where Next.js blocks Clicking this button should result in an error where Next.js blocks a
a javascript URL javascript URL
</p> </p>
<button onClick={() => router.push(DANGEROUS_JAVASCRIPT_URL)}> <button onClick={() => router.push(DANGEROUS_JAVASCRIPT_URL)}>
push javascript URL push javascript URL
...@@ -20,7 +19,6 @@ export default function Page() { ...@@ -20,7 +19,6 @@ export default function Page() {
<footer> <footer>
<Link href="/pages/safe">Safe Page</Link> <Link href="/pages/safe">Safe Page</Link>
</footer> </footer>
</body> </div>
</html>
) )
} }
...@@ -6,12 +6,11 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url' ...@@ -6,12 +6,11 @@ import { DANGEROUS_JAVASCRIPT_URL } from '../../bad-url'
export default function Page() { export default function Page() {
const router = useRouter() const router = useRouter()
return ( return (
<html> <div>
<body>
<main> <main>
<p> <p>
Clicking this button should result in an error where Next.js blocks Clicking this button should result in an error where Next.js blocks a
a javascript URL javascript URL
</p> </p>
<button onClick={() => router.replace(DANGEROUS_JAVASCRIPT_URL)}> <button onClick={() => router.replace(DANGEROUS_JAVASCRIPT_URL)}>
replace javascript URL replace javascript URL
...@@ -20,7 +19,6 @@ export default function Page() { ...@@ -20,7 +19,6 @@ export default function Page() {
<footer> <footer>
<Link href="/pages/safe">Safe Page</Link> <Link href="/pages/safe">Safe Page</Link>
</footer> </footer>
</body> </div>
</html>
) )
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment