From 2e668e6b31766e83968c5c596b5e5913daf25094 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 20 Jan 2020 14:47:42 -0500 Subject: [PATCH 1/2] Remove `native-url` (#10176) * Remove `native-url` * Increase sizes --- packages/next/build/webpack-config.ts | 2 +- packages/next/package.json | 1 - test/integration/size-limit/test/index.test.js | 4 ++-- yarn.lock | 7 ------- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 3c8aaf0a4d067..2352a9985f562 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -87,7 +87,7 @@ function getOptimizedAliases(isServer: boolean): { [pkg: string]: string } { 'object.assign/shim': path.join(shimAssign, 'shim.js'), // Replace: full URL polyfill with platform-based polyfill - url: require.resolve('native-url'), + // url: require.resolve('native-url'), } } diff --git a/packages/next/package.json b/packages/next/package.json index b233f2e3ff747..c380214558dd7 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -109,7 +109,6 @@ "lru-cache": "5.1.1", "mini-css-extract-plugin": "0.8.0", "mkdirp": "0.5.1", - "native-url": "0.2.4", "node-fetch": "2.6.0", "object-assign": "4.1.1", "ora": "3.4.0", diff --git a/test/integration/size-limit/test/index.test.js b/test/integration/size-limit/test/index.test.js index 9653eda05a8a8..10ae42c581ad4 100644 --- a/test/integration/size-limit/test/index.test.js +++ b/test/integration/size-limit/test/index.test.js @@ -81,7 +81,7 @@ describe('Production response size', () => { ) // These numbers are without gzip compression! - const delta = responseSizeKilobytes - 228 + const delta = responseSizeKilobytes - 234 expect(delta).toBeLessThanOrEqual(0) // don't increase size expect(delta).toBeGreaterThanOrEqual(-1) // don't decrease size without updating target }) @@ -101,7 +101,7 @@ describe('Production response size', () => { ) // These numbers are without gzip compression! - const delta = responseSizeKilobytes - 196 + const delta = responseSizeKilobytes - 203 expect(delta).toBeLessThanOrEqual(0) // don't increase size expect(delta).toBeGreaterThanOrEqual(-1) // don't decrease size without updating target }) diff --git a/yarn.lock b/yarn.lock index dd3fd79329695..788305cc43a4e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10079,13 +10079,6 @@ native-or-bluebird@^1.2.0: resolved "https://registry.yarnpkg.com/native-or-bluebird/-/native-or-bluebird-1.2.0.tgz#39c47bfd7825d1fb9ffad32210ae25daadf101c9" integrity sha1-OcR7/Xgl0fuf+tMiEK4l2q3xAck= -native-url@0.2.4: - version "0.2.4" - resolved "https://registry.yarnpkg.com/native-url/-/native-url-0.2.4.tgz#37623b3db2c7bb6670e50e379634248ba5ca9d90" - integrity sha512-McE+8BrgMw2ANypdYX9s1L+aUkbWDCEtsBGIbs8TfKBfQrFcZ2jMXX9LxGjOIOtoRXkwLTSlz38XHm8J3U6hgQ== - dependencies: - querystring "^0.2.0" - natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" From eb38d223e69e00aad2ff1b665e21a7735a21f90d Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 20 Jan 2020 15:16:18 -0500 Subject: [PATCH 2/2] Test Query String Behavior (#10102) * Test Query String Behavior * Test Query String with % * Test Query String With LF * Update test * Consolidate * Consolidate --- .../query-with-encoding/pages/index.js | 7 + .../query-with-encoding/pages/newline.js | 15 ++ .../query-with-encoding/pages/percent.js | 15 ++ .../query-with-encoding/pages/space.js | 15 ++ .../query-with-encoding/test/index.test.js | 193 ++++++++++++++++++ 5 files changed, 245 insertions(+) create mode 100644 test/integration/query-with-encoding/pages/index.js create mode 100644 test/integration/query-with-encoding/pages/newline.js create mode 100644 test/integration/query-with-encoding/pages/percent.js create mode 100644 test/integration/query-with-encoding/pages/space.js create mode 100644 test/integration/query-with-encoding/test/index.test.js diff --git a/test/integration/query-with-encoding/pages/index.js b/test/integration/query-with-encoding/pages/index.js new file mode 100644 index 0000000000000..5abbac3c14b81 --- /dev/null +++ b/test/integration/query-with-encoding/pages/index.js @@ -0,0 +1,7 @@ +const Index = ({ query }) => ( +
{JSON.stringify(query)}
+) + +Index.getInitialProps = ({ query }) => ({ query }) + +export default Index diff --git a/test/integration/query-with-encoding/pages/newline.js b/test/integration/query-with-encoding/pages/newline.js new file mode 100644 index 0000000000000..f54a15a0ec780 --- /dev/null +++ b/test/integration/query-with-encoding/pages/newline.js @@ -0,0 +1,15 @@ +import Link from 'next/link' + +const Another = () => ( +
+ + Hello LF + +
+ + Hello Complex + +
+) + +export default Another diff --git a/test/integration/query-with-encoding/pages/percent.js b/test/integration/query-with-encoding/pages/percent.js new file mode 100644 index 0000000000000..293f399e3dad6 --- /dev/null +++ b/test/integration/query-with-encoding/pages/percent.js @@ -0,0 +1,15 @@ +import Link from 'next/link' + +const Another = () => ( +
+ + Hello % + +
+ + Hello Complex + +
+) + +export default Another diff --git a/test/integration/query-with-encoding/pages/space.js b/test/integration/query-with-encoding/pages/space.js new file mode 100644 index 0000000000000..5c988ec397099 --- /dev/null +++ b/test/integration/query-with-encoding/pages/space.js @@ -0,0 +1,15 @@ +import Link from 'next/link' + +const Another = () => ( +
+ + Hello Space + +
+ + Hello Complex + +
+) + +export default Another diff --git a/test/integration/query-with-encoding/test/index.test.js b/test/integration/query-with-encoding/test/index.test.js new file mode 100644 index 0000000000000..32309b8a73312 --- /dev/null +++ b/test/integration/query-with-encoding/test/index.test.js @@ -0,0 +1,193 @@ +/* eslint-env jest */ +/* global jasmine */ +import { + nextBuild, + nextServer, + startApp, + stopApp, + waitFor, +} from 'next-test-utils' +import webdriver from 'next-webdriver' +import { join } from 'path' + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 + +const appDir = join(__dirname, '..') + +let appPort +let app +let server + +describe('Query String with Encoding', () => { + beforeAll(async () => { + await nextBuild(appDir) + app = nextServer({ + dir: join(__dirname, '../'), + dev: false, + quiet: true, + }) + + server = await startApp(app) + appPort = server.address().port + }) + afterAll(() => stopApp(server)) + + describe('new line', () => { + it('should have correct query on SSR', async () => { + const browser = await webdriver(appPort, '/?test=abc%0A') + try { + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"test":"abc\\n"}') + } finally { + await browser.close() + } + }) + + it('should have correct query on Router#push', async () => { + const browser = await webdriver(appPort, '/') + try { + await waitFor(2000) + await browser.eval( + `window.next.router.push({pathname:'/',query:{abc:'def\\n'}})` + ) + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"abc":"def\\n"}') + } finally { + await browser.close() + } + }) + + it('should have correct query on simple client-side ', async () => { + const browser = await webdriver(appPort, '/newline') + try { + await waitFor(2000) + await browser.elementByCss('#hello-lf').click() + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"another":"hello\\n"}') + } finally { + await browser.close() + } + }) + + it('should have correct query on complex client-side ', async () => { + const browser = await webdriver(appPort, '/newline') + try { + await waitFor(2000) + await browser.elementByCss('#hello-complex').click() + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"complex":"yes\\n"}') + } finally { + await browser.close() + } + }) + }) + + describe('trailing space', () => { + it('should have correct query on SSR', async () => { + const browser = await webdriver(appPort, '/?test=abc%20') + try { + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"test":"abc "}') + } finally { + await browser.close() + } + }) + + it('should have correct query on Router#push', async () => { + const browser = await webdriver(appPort, '/') + try { + await waitFor(2000) + await browser.eval( + `window.next.router.push({pathname:'/',query:{abc:'def '}})` + ) + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"abc":"def "}') + } finally { + await browser.close() + } + }) + + it('should have correct query on simple client-side ', async () => { + const browser = await webdriver(appPort, '/space') + try { + await waitFor(2000) + await browser.elementByCss('#hello-space').click() + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"another":"hello "}') + } finally { + await browser.close() + } + }) + + it('should have correct query on complex client-side ', async () => { + const browser = await webdriver(appPort, '/space') + try { + await waitFor(2000) + await browser.elementByCss('#hello-complex').click() + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"complex":"yes "}') + } finally { + await browser.close() + } + }) + }) + + describe('percent', () => { + it('should have correct query on SSR', async () => { + const browser = await webdriver(appPort, '/?test=abc%25') + try { + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"test":"abc%"}') + } finally { + await browser.close() + } + }) + + it('should have correct query on Router#push', async () => { + const browser = await webdriver(appPort, '/') + try { + await waitFor(2000) + await browser.eval( + `window.next.router.push({pathname:'/',query:{abc:'def%'}})` + ) + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"abc":"def%"}') + } finally { + await browser.close() + } + }) + + it('should have correct query on simple client-side ', async () => { + const browser = await webdriver(appPort, '/percent') + try { + await waitFor(2000) + await browser.elementByCss('#hello-percent').click() + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"another":"hello%"}') + } finally { + await browser.close() + } + }) + + it('should have correct query on complex client-side ', async () => { + const browser = await webdriver(appPort, '/percent') + try { + await waitFor(2000) + await browser.elementByCss('#hello-complex').click() + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"complex":"yes%"}') + } finally { + await browser.close() + } + }) + }) +})