Skip to content

Commit

Permalink
Plus sign not decoded correctly when adding and then getting nodePara…
Browse files Browse the repository at this point in the history
…ms (#2901)

* Add more options to desanitize

* Bring back single quotes in scripts/package

* WIP

* Clean up

* Clean up

* Add decode

* Clean up

* Update a test

* Change back in " to '

* WIP

* WIP

* Update .gitignore

* Update angular.json

* Update angular.json

* Update luigi-client-ux-alerts-i18n.spec.js

* Update luigi-client-ux-manager-features.spec.js

* Update drawer.component.html

* Update drawer.component.html

* Update drawer.component.html

* Update drawer.component.html

* Update settings.component.html

* Revert package.jsons

* Revert package.jsons

* Revert package.jsons

* Revert package-lock.json

* Remove package-lock.json

* Remove package-lock.json

* Remove package-lock.json

* Add a test case for parseParams in routing.js

Co-authored-by: Ndricim Rrapi <ndricim.rrapi@sap.com>
  • Loading branch information
wdoberschuetz and ndricimrr authored Nov 4, 2022
1 parent facf8e5 commit c62035a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
10 changes: 2 additions & 8 deletions core/src/utilities/helpers/routing-helpers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// Helper methods for 'routing.js' file. They don't require any method from 'routing.js' but are required by them.
// They are also rarely used directly from outside of 'routing.js'
import { LuigiConfig, LuigiFeatureToggles, LuigiI18N, LuigiRouting } from '../../core-api';
import {
AsyncHelpers,
EscapingHelpers,
EventListenerHelpers,
GenericHelpers,
IframeHelpers,
} from './';
import { AsyncHelpers, EscapingHelpers, EventListenerHelpers, GenericHelpers, IframeHelpers } from './';
import { Routing } from '../../services/routing';

class RoutingHelpersClass {
Expand Down Expand Up @@ -54,7 +48,7 @@ class RoutingHelpersClass {
parseParams(paramsString) {
if (!paramsString) return {};
const result = {};
const viewParamString = paramsString;
const viewParamString = paramsString.replace(/\+/g, ' ');
const pairs = viewParamString ? viewParamString.split('&') : null;
if (pairs) {
pairs.forEach(pairString => {
Expand Down
10 changes: 10 additions & 0 deletions core/test/core-api/routing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ describe('Luigi routing', function() {
RoutingHelpers.modifySearchParams({ test: 'tets', luigi: 'rocks' }, searchParams, '~');
assert.equal(searchParams.toString(), '%7Emario=rocks&%7Etest=tets&%7Eluigi=rocks');
});
it('modifySearchParams with space', () => {
const searchParams = new URLSearchParams('~mario=rocks');
RoutingHelpers.modifySearchParams({ test: 'test abc' }, searchParams, '~');
assert.equal(searchParams.toString(), '%7Emario=rocks&%7Etest=test+abc');
});
it('modifySearchParams with a plus sign', () => {
const searchParams = new URLSearchParams('~mario=rocks');
RoutingHelpers.modifySearchParams({ test: 'test+abc' }, searchParams, '~');
assert.equal(searchParams.toString(), '%7Emario=rocks&%7Etest=test%2Babc');
});
});

describe('addNodeParams', () => {
Expand Down
18 changes: 13 additions & 5 deletions core/test/utilities/helpers/routing-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ describe('Routing-helpers', () => {
const node = {
context,
externalLink: { url: 'https://someurl.com', sameWindow: false },
label: "External link"
label: 'External link'
};
it('get context from node', () => {
assert.deepEqual(RoutingHelpers.getContext(node, undefined), context);
Expand Down Expand Up @@ -457,9 +457,9 @@ describe('Routing-helpers', () => {
};
sinon.stub(RoutingHelpers, 'getRouteLink');
sinon
.stub(LuigiConfig, 'getConfigValue')
.withArgs('routing.useHashRouting')
.returns(false);
.stub(LuigiConfig, 'getConfigValue')
.withArgs('routing.useHashRouting')
.returns(false);
});
afterEach(() => {
sinon.restore();
Expand All @@ -472,7 +472,7 @@ describe('Routing-helpers', () => {
pathSegment: 'something-else'
};
RoutingHelpers.getRouteLink.returns({ url });
expect(RoutingHelpers.calculateNodeHref(node , {})).to.equal('https://luigi-project.io');
expect(RoutingHelpers.calculateNodeHref(node, {})).to.equal('https://luigi-project.io');
});
});
describe('getNodeHref', () => {
Expand Down Expand Up @@ -548,6 +548,14 @@ describe('Routing-helpers', () => {
mockParams = '';
expect(RoutingHelpers.parseParams(mockParams)).to.deep.equal({});
});

it('return pairs of params with a space and a plus', () => {
mockParams = 'test=true+abc&foo=bar%2Babc';
assert.deepEqual(RoutingHelpers.parseParams(mockParams), {
test: 'true abc',
foo: 'bar+abc'
});
});
});

describe('findViewGroup', () => {
Expand Down
5 changes: 1 addition & 4 deletions test/e2e-test-application/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ import { ViewGroupComponent } from './project/view-group/view-group.component';
ViewGroupComponent
],
imports: [BrowserModule, FormsModule, AppRoutingModule],
providers: [
LuigiContextService,
LuigiAutoNavigationService
],
providers: [LuigiContextService, LuigiAutoNavigationService],
bootstrap: [AppComponent]
})
export class AppModule {}

0 comments on commit c62035a

Please sign in to comment.