Skip to content

Commit

Permalink
utils/v4/url API + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
delchev committed Mar 2, 2019
1 parent f324411 commit b9a2ace
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ public void registerModules() {
TEST_MODULES.add("utils/v4/escape/unescapeJson.js");
TEST_MODULES.add("utils/v4/escape/escapeXml.js");
TEST_MODULES.add("utils/v4/escape/unescapeXml.js");

TEST_MODULES.add("utils/v4/url/encode.js");
TEST_MODULES.add("utils/v4/url/decode.js");
TEST_MODULES.add("utils/v4/url/escape.js");
TEST_MODULES.add("utils/v4/url/escapePath.js");
TEST_MODULES.add("utils/v4/url/escapeForm.js");
}

public void runSuite(IJavascriptEngineExecutor executor, IRepository repository)
Expand Down
16 changes: 16 additions & 0 deletions api/api-facade/api-tests/src/main/resources/utils/v4/url/decode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2010-2019 SAP and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* SAP - initial API and implementation
*/
var url = require('utils/v4/url');

var input = '%3C%21%5BCDATA%5B%3Cmeta+http-equiv%3D%22refresh%22+content%3D%220%3Burl%3Djavascript%3Adocument.vulnerable%3Dtrue%3B%22%3E%5D%5D%3E';
var result = url.decode(input, 'UTF-8');

result == '<![CDATA[<meta http-equiv="refresh" content="0;url=javascript:document.vulnerable=true;">]]>'
16 changes: 16 additions & 0 deletions api/api-facade/api-tests/src/main/resources/utils/v4/url/encode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2010-2019 SAP and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* SAP - initial API and implementation
*/
var url = require('utils/v4/url');

var input = '<![CDATA[<meta http-equiv="refresh" content="0;url=javascript:document.vulnerable=true;">]]>';
var result = url.encode(input, 'UTF-8');

result == '%3C%21%5BCDATA%5B%3Cmeta+http-equiv%3D%22refresh%22+content%3D%220%3Burl%3Djavascript%3Adocument.vulnerable%3Dtrue%3B%22%3E%5D%5D%3E';
16 changes: 16 additions & 0 deletions api/api-facade/api-tests/src/main/resources/utils/v4/url/escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2010-2019 SAP and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* SAP - initial API and implementation
*/
var url = require('utils/v4/url');

var input = 'http://www.test.com?var1=abc123&var2=123 456&var3=стойност';
var result = url.escape(input);
console.log(result);
result == 'http://www.test.com?var1=abc123&var2=123%20456&var3=%D1%81%D1%82%D0%BE%D0%B9%D0%BD%D0%BE%D1%81%D1%82';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2010-2019 SAP and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* SAP - initial API and implementation
*/
var url = require('utils/v4/url');

var input = 'http://www.test.com?var1=abc123&var2=123 456&var3=стойност';
var result = url.escapeForm(input);
console.log(result);
result == 'http%3A%2F%2Fwww.test.com%3Fvar1%3Dabc123%26var2%3D123+456%26var3%3D%D1%81%D1%82%D0%BE%D0%B9%D0%BD%D0%BE%D1%81%D1%82';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2010-2019 SAP and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* SAP - initial API and implementation
*/
var url = require('utils/v4/url');

var input = 'http://www.test.com?var1=abc123&var2=123 456&var3=стойност';
var result = url.escapePath(input);
console.log(result);
result == 'http:%2F%2Fwww.test.com%3Fvar1=abc123&var2=123%20456&var3=%D1%81%D1%82%D0%BE%D0%B9%D0%BD%D0%BE%D1%81%D1%82';
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,29 @@ public static final String escape(String input) {
return UrlEscapers.urlFragmentEscaper().escape(input);

}

/**
* Escape URL path
*
* @param input
* the input string
* @return escaped input
*/
public static final String escapePath(String input) {
return UrlEscapers.urlPathSegmentEscaper().escape(input);

}

/**
* Escape URL fragments
*
* @param input
* the input string
* @return escaped input
*/
public static final String escapeForm(String input) {
return UrlEscapers.urlFormParameterEscaper().escape(input);

}

}
35 changes: 35 additions & 0 deletions api/api-javascript/api-utils/src/main/resources/utils/v4/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2010-2019 SAP and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* SAP - initial API and implementation
*/

exports.encode = function(input, charset) {
var output = org.eclipse.dirigible.api.v3.utils.UrlFacade.encode(input, charset);
return output;
};

exports.decode = function(input, charset) {
var output = org.eclipse.dirigible.api.v3.utils.UrlFacade.decode(input, charset);
return output;
};

exports.escape = function(input) {
var output = org.eclipse.dirigible.api.v3.utils.UrlFacade.escape(input);
return output;
};

exports.escapePath = function(input) {
var output = org.eclipse.dirigible.api.v3.utils.UrlFacade.escapePath(input);
return output;
};

exports.escapeForm = function(input) {
var output = org.eclipse.dirigible.api.v3.utils.UrlFacade.escapeForm(input);
return output;
};

0 comments on commit b9a2ace

Please sign in to comment.