Skip to content

Commit

Permalink
Undo changes from 78f016 and 0fe9cb
Browse files Browse the repository at this point in the history
This is a temporary change so we can get the master branch back into a
state to cut 4.x releases.
  • Loading branch information
mjackson committed Sep 11, 2019
1 parent b141a1b commit 7b8ab30
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 5 deletions.
15 changes: 15 additions & 0 deletions modules/LocationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ export function createLocation(path, state, key, currentLocation) {
location.state = state;
}

try {
location.pathname = decodeURI(location.pathname);
} catch (e) {
if (e instanceof URIError) {
throw new URIError(
'Pathname "' +
location.pathname +
'" could not be decoded. ' +
'This is likely caused by an invalid percent-encoding.'
);
} else {
throw e;
}
}

if (key) location.key = key;

if (currentLocation) {
Expand Down
12 changes: 12 additions & 0 deletions modules/__tests__/BrowserHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ describe('a browser history', () => {
});
});

describe('push with an invalid pathname (bad percent-encoding)', () => {
it('throws an error', done => {
TestSequences.PushInvalidPathname(history, done);
});
});

describe('push with a unicode path string', () => {
it('creates a location with decoded properties', done => {
TestSequences.PushUnicodeLocation(history, done);
Expand All @@ -102,6 +108,12 @@ describe('a browser history', () => {
});
});

describe('replace with an invalid pathname (bad percent-encoding)', () => {
it('throws an error', done => {
TestSequences.ReplaceInvalidPathname(history, done);
});
});

describe('replace state', () => {
it('calls change listeners with the new location', done => {
TestSequences.ReplaceState(history, done);
Expand Down
12 changes: 12 additions & 0 deletions modules/__tests__/HashHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ describe('a hash history', () => {
});
});

describe('push with an invalid pathname (bad percent-encoding)', () => {
it('throws an error', done => {
TestSequences.PushInvalidPathname(history, done);
});
});

describe('push with a unicode path string', () => {
it('creates a location with decoded properties', done => {
TestSequences.PushUnicodeLocation(history, done);
Expand All @@ -105,6 +111,12 @@ describe('a hash history', () => {
});
});

describe('replace with an invalid pathname (bad percent-encoding)', () => {
it('throws an error', done => {
TestSequences.ReplaceInvalidPathname(history, done);
});
});

describe('replace state', () => {
it('calls change listeners with the new location and emits a warning', done => {
TestSequences.ReplaceStateWarning(history, done);
Expand Down
12 changes: 12 additions & 0 deletions modules/__tests__/MemoryHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ describe('a memory history', () => {
});
});

describe('push with an invalid pathname (bad percent-encoding)', () => {
it('throws an error', done => {
TestSequences.PushInvalidPathname(history, done);
});
});

describe('push with a unicode path string', () => {
it('creates a location with decoded properties', done => {
TestSequences.PushUnicodeLocation(history, done);
Expand All @@ -99,6 +105,12 @@ describe('a memory history', () => {
});
});

describe('replace with an invalid pathname (bad percent-encoding)', () => {
it('throws an error', done => {
TestSequences.ReplaceInvalidPathname(history, done);
});
});

describe('replace state', () => {
it('calls change listeners with the new location', done => {
TestSequences.ReplaceState(history, done);
Expand Down
5 changes: 2 additions & 3 deletions modules/__tests__/TestSequences/LocationPathnameAlwaysSame.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ export default function(history, done) {
},
location => {
expect(location).toMatchObject({
pathname: '/%E6%AD%B4%E5%8F%B2'
pathname: '/歴史'
});

// encoded object
const pathname = '/%E6%AD%B4%E5%8F%B2';
history.replace({ pathname });
},
location => {
expect(location).toMatchObject({
pathname: '/%E6%AD%B4%E5%8F%B2'
pathname: '/歴史'
});
// unencoded string
const pathname = '/歴史';
Expand Down
4 changes: 2 additions & 2 deletions modules/__tests__/TestSequences/PushEncodedLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export default function(history, done) {
pathname: '/'
});

const pathname = '/%E6%AD%B4%E5%8F%B2';
const pathname = '/歴史';
const search = '?%E3%82%AD%E3%83%BC=%E5%80%A4';
const hash = '#%E3%83%8F%E3%83%83%E3%82%B7%E3%83%A5';
history.push(pathname + search + hash);
},
(location, action) => {
expect(action).toBe('PUSH');
expect(location).toMatchObject({
pathname: '/%E6%AD%B4%E5%8F%B2',
pathname: '/歴史',
search: '?%E3%82%AD%E3%83%BC=%E5%80%A4',
hash: '#%E3%83%8F%E3%83%83%E3%82%B7%E3%83%A5'
});
Expand Down
17 changes: 17 additions & 0 deletions modules/__tests__/TestSequences/PushInvalidPathname.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import expect from 'expect';

import execSteps from './execSteps';

export default function(history, done) {
const steps = [
() => {
expect(() => {
history.push('/hello%');
}).toThrow(
'Pathname "/hello%" could not be decoded. This is likely caused by an invalid percent-encoding.'
);
}
];

execSteps(steps, history, done);
}
17 changes: 17 additions & 0 deletions modules/__tests__/TestSequences/ReplaceInvalidPathname.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import expect from 'expect';

import execSteps from './execSteps';

export default function(history, done) {
const steps = [
() => {
expect(() => {
history.replace('/hello%');
}).toThrow(
'Pathname "/hello%" could not be decoded. This is likely caused by an invalid percent-encoding.'
);
}
];

execSteps(steps, history, done);
}
2 changes: 2 additions & 0 deletions modules/__tests__/TestSequences/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export {
} from './LocationPathnameAlwaysSame';
export { default as NoslashHashPathCoding } from './NoslashHashPathCoding';
export { default as PushEncodedLocation } from './PushEncodedLocation';
export { default as PushInvalidPathname } from './PushInvalidPathname';
export { default as PushNewLocation } from './PushNewLocation';
export { default as PushMissingPathname } from './PushMissingPathname';
export { default as PushSamePath } from './PushSamePath';
Expand All @@ -33,6 +34,7 @@ export { default as PushState } from './PushState';
export { default as PushStateWarning } from './PushStateWarning';
export { default as PushRelativePathname } from './PushRelativePathname';
export { default as PushUnicodeLocation } from './PushUnicodeLocation';
export { default as ReplaceInvalidPathname } from './ReplaceInvalidPathname';
export { default as ReplaceNewLocation } from './ReplaceNewLocation';
export { default as ReplaceSamePath } from './ReplaceSamePath';
export { default as ReplaceState } from './ReplaceState';
Expand Down

0 comments on commit 7b8ab30

Please sign in to comment.