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

Make PathUtils recognize query and splat values containing newlines #1166

Closed
wants to merge 1 commit into from
Closed
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 modules/PathUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var invariant = require('react/lib/invariant');
var assign = require('object-assign');
var qs = require('qs');

var queryMatcher = /\?(.*)$/;
var queryMatcher = /\?([\s\S]*)$/;

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
Expand All @@ -25,7 +25,7 @@ function _compilePattern(pattern) {
escapedSource += '([^/?#]+)';
paramNames.push(match[1]);
} else if (match[0] === '*') {
escapedSource += '(.*?)';
escapedSource += '([\\s\\S]*?)';
paramNames.push('splat');
} else if (match[0] === '(') {
escapedSource += '(?:';
Expand Down
15 changes: 15 additions & 0 deletions modules/__tests__/PathUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ describe('PathUtils.extractParams', function () {
expect(PathUtils.extractParams('/files/*', '/files/my/photo.jpg')).toEqual({ splat: 'my/photo.jpg' });
expect(PathUtils.extractParams('/files/*', '/files/my/photo.jpg.zip')).toEqual({ splat: 'my/photo.jpg.zip' });
expect(PathUtils.extractParams('/files/*.jpg', '/files/my/photo.jpg')).toEqual({ splat: 'my/photo' });
expect(PathUtils.extractParams('/files/*.jpg', '/files/my/new\nline.jpg')).toEqual({ splat: 'my/new\nline' });
});
});

Expand Down Expand Up @@ -287,6 +288,20 @@ describe('PathUtils.extractQuery', function () {
it('properly handles encoded ampersands', function () {
expect(PathUtils.extractQuery('/?id=a%26b')).toEqual({ id: 'a&b' });
});

it('properly handles raw newlines', function () {
expect(PathUtils.extractQuery('/?id=a\nb')).toEqual({ id: 'a\nb' });
expect(PathUtils.extractQuery('/?id=a\rb')).toEqual({ id: 'a\rb' });
expect(PathUtils.extractQuery('/?id=a\r\nb')).toEqual({ id: 'a\r\nb' });
expect(PathUtils.extractQuery('/?id=a\n\rb')).toEqual({ id: 'a\n\rb' });
});

it('properly handles encoded newlines', function () {
expect(PathUtils.extractQuery('/?id=a%0Ab')).toEqual({ id: 'a\nb' });
expect(PathUtils.extractQuery('/?id=a%0Db')).toEqual({ id: 'a\rb' });
expect(PathUtils.extractQuery('/?id=a%0D%0Ab')).toEqual({ id: 'a\r\nb' });
expect(PathUtils.extractQuery('/?id=a%0A%0Db')).toEqual({ id: 'a\n\rb' });
});
});

describe('when the path does not contain a query string', function () {
Expand Down