Skip to content

Commit 081fe3f

Browse files
committed
Deal with security alerts in regex
* Updated README Fixes #183
1 parent 1f3a172 commit 081fe3f

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ stamp-web-aurelia is the web front-end for managing collections of stamps and le
1515

1616
![Screen shot showing Editing in Stamp-Web](https://i.imgur.com/1f8SF9h.png)
1717

18-
## Build Status
19-
20-
![Build Status](https://drake-server.ddns.net:9443/build/stamp-web-aurelia.svg)
21-
2218

2319
## Demo Server
2420

@@ -89,7 +85,7 @@ To run the unit tests, first ensure that you have followed the steps above in or
8985

9086
## Running the Integration Tests
9187

92-
npm fddWebdriver for NodeJS is used for the integration tests. This project has been moved to [stamp-web-selenium](https://github.com/stamp-web/stamp-web-selenium)
88+
Webdriver for NodeJS is used for the integration tests. This project has been moved to [stamp-web-selenium](https://github.com/stamp-web/stamp-web-selenium)
9389

9490

9591
## Test Statistics

src/util/location-helper.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
Copyright 2017 Jason Drake
2+
Copyright 2022 Jason Drake
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -22,12 +22,12 @@ function LocationHelperFn() {
2222
loadResource: (filename, filetype = 'js') => {
2323
return new Promise((resolve,reject) => {
2424
let fileRef;
25-
if (filetype == 'js') {
25+
if (filetype === 'js') {
2626
fileRef = document.createElement('script');
2727
fileRef.setAttribute('type', 'text/javascript');
2828
fileRef.setAttribute('src', filename);
2929
}
30-
else if (filetype == 'css') {
30+
else if (filetype === 'css') {
3131
fileRef = document.createElement('link');
3232
fileRef.setAttribute('rel', 'stylesheet');
3333
fileRef.setAttribute('type', 'text/css');
@@ -42,20 +42,16 @@ function LocationHelperFn() {
4242
};
4343
_.defer(() => {
4444
document.getElementsByTagName("head")[0].appendChild(fileRef);
45-
})
46-
45+
});
4746
}
4847
});
4948
},
5049

51-
getQueryParameter: (key, default_) => {
52-
if (default_ == null) {
53-
default_ = null;
54-
}
55-
key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
56-
key = key.replace("$", "\\$");
57-
var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
58-
var qs = regex.exec(window.location.href);
50+
getQueryParameter: (key, default_ = null) => {
51+
key = key.replace(/[\[]/g, "\\\[").replace(/[\]]/g, "\\\]");
52+
key = key.replace(/\$/g, "\\$");
53+
let regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
54+
let qs = regex.exec(window.location.href);
5955
if (qs == null) {
6056
return default_;
6157
} else {

test/unit/util/location-helper.spec.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
Copyright 2019 Jason Drake
2+
Copyright 2022 Jason Drake
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -13,13 +13,11 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import {EnumeratedTypeHelper, ConditionHelper, StampHelper, Condition, Defects} from 'util/common-models';
17-
import _ from 'lodash';
1816
import {LocationHelper} from "../../../src/util/location-helper";
1917

2018
describe('LocationHelper test suite', () => {
2119

22-
describe('resolvePath tests', () => {
20+
describe('resolvePath', () => {
2321

2422
it('use default for empty', () => {
2523
let v = LocationHelper.resolvePath(undefined, 'default');
@@ -39,6 +37,40 @@ describe('LocationHelper test suite', () => {
3937
let v = LocationHelper.resolvePath({value: 'https://site.com/some/path'}, 'default');
4038
expect(v).toBe('https://site.com/some/path/');
4139
});
40+
});
41+
42+
describe('getQueryParameter', () => {
43+
44+
afterEach(() => {
45+
jest.resetAllMocks();
46+
});
47+
48+
let mockLocation = loc => {
49+
const location = new URL(loc);
50+
location.assign = jest.fn();
51+
location.replace = jest.fn();
52+
location.reload = jest.fn();
53+
54+
delete window.location;
55+
window.location = location;
56+
};
4257

58+
it('verify extraction of $filter parameter with $filter in parameter value', () => {
59+
mockLocation('http://localhost:9000/#/?$filter=(countryName%20eq%20%27$filter%27)&$orderby=number%20asc&$top=1000');
60+
let q = LocationHelper.getQueryParameter('$filter');
61+
expect(q).toBe('(countryName eq \'$filter\')');
62+
});
63+
64+
it('no parameter in location', () => {
65+
mockLocation('http://localhost:9000/#/?$orderby=number%20asc&$top=1000');
66+
let q = LocationHelper.getQueryParameter('$filter');
67+
expect(q).toBeNull();
68+
});
69+
70+
it('no parameter in location with a default', () => {
71+
mockLocation('http://localhost:9000/#/?$orderby=number%20asc&$top=1000');
72+
let q = LocationHelper.getQueryParameter('$filter', 'someDefault');
73+
expect(q).toBe('someDefault');
74+
});
4375
});
4476
});

0 commit comments

Comments
 (0)