File tree Expand file tree Collapse file tree 3 files changed +102
-2
lines changed
Expand file tree Collapse file tree 3 files changed +102
-2
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,13 @@ class URLDecode extends Operation {
2323 this . infoURL = "https://wikipedia.org/wiki/Percent-encoding" ;
2424 this . inputType = "string" ;
2525 this . outputType = "string" ;
26- this . args = [ ] ;
26+ this . args = [
27+ {
28+ "name" : "Treat \"+\" as space" ,
29+ "type" : "boolean" ,
30+ "value" : true
31+ } ,
32+ ] ;
2733 this . checks = [
2834 {
2935 pattern : ".*(?:%[\\da-f]{2}.*){4}" ,
@@ -39,7 +45,8 @@ class URLDecode extends Operation {
3945 * @returns {string }
4046 */
4147 run ( input , args ) {
42- const data = input . replace ( / \+ / g, "%20" ) ;
48+ const plusIsSpace = args [ 0 ] ;
49+ const data = plusIsSpace ? input . replace ( / \+ / g, "%20" ) : input ;
4350 try {
4451 return decodeURIComponent ( data ) ;
4552 } catch ( err ) {
Original file line number Diff line number Diff line change @@ -163,6 +163,7 @@ import "./tests/TranslateDateTimeFormat.mjs";
163163import "./tests/Typex.mjs" ;
164164import "./tests/UnescapeString.mjs" ;
165165import "./tests/Unicode.mjs" ;
166+ import "./tests/URLEncodeDecode.mjs" ;
166167import "./tests/RSA.mjs" ;
167168import "./tests/CBOREncode.mjs" ;
168169import "./tests/CBORDecode.mjs" ;
Original file line number Diff line number Diff line change 1+ /**
2+ * URLEncode and URLDecode tests.
3+ *
4+ * @author es45411 [[email protected] ] 5+ *
6+ * @copyright Crown Copyright 2018
7+ * @license Apache-2.0
8+ */
9+
10+ import TestRegister from "../../lib/TestRegister.mjs" ;
11+
12+ TestRegister . addTests ( [
13+ // URL Decode
14+ {
15+ name : "URLDecode: nothing" ,
16+ input : "" ,
17+ expectedOutput : "" ,
18+ recipeConfig : [
19+ {
20+ op : "URL Decode" ,
21+ args : [ ] ,
22+ } ,
23+ ] ,
24+ } ,
25+ {
26+ name : "URLDecode: spaces without special chars" ,
27+ input : "Hello%20world%21" ,
28+ expectedOutput : "Hello world!" ,
29+ recipeConfig : [
30+ {
31+ op : "URL Decode" ,
32+ args : [ ] ,
33+ } ,
34+ ] ,
35+ } ,
36+ {
37+ name : "URLDecode: spaces with special chars" ,
38+ input : "Hello%20world!" ,
39+ expectedOutput : "Hello world!" ,
40+ recipeConfig : [
41+ {
42+ op : "URL Decode" ,
43+ args : [ ] ,
44+ } ,
45+ ] ,
46+ } ,
47+ {
48+ name : "URLDecode: decode plus as space" ,
49+ input : "Hello%20world!" ,
50+ expectedOutput : "Hello world!" ,
51+ recipeConfig : [
52+ {
53+ op : "URL Decode" ,
54+ args : [ ] ,
55+ } ,
56+ ] ,
57+ } ,
58+ // URL Encode
59+ {
60+ name : "URLEncode: nothing" ,
61+ input : "" ,
62+ expectedOutput : "" ,
63+ recipeConfig : [
64+ {
65+ op : "URL Encode" ,
66+ args : [ ] ,
67+ } ,
68+ ] ,
69+ } ,
70+ {
71+ name : "URLEncode: spaces without special chars" ,
72+ input : "Hello world!" ,
73+ expectedOutput : "Hello%20world!" ,
74+ recipeConfig : [
75+ {
76+ op : "URL Encode" ,
77+ args : [ ] ,
78+ } ,
79+ ] ,
80+ } ,
81+ {
82+ name : "URLEncode: spaces with special chars" ,
83+ input : "Hello world!" ,
84+ expectedOutput : "Hello%20world%21" ,
85+ recipeConfig : [
86+ {
87+ op : "URL Encode" ,
88+ args : [ true ] ,
89+ } ,
90+ ] ,
91+ } ,
92+ ] ) ;
You can’t perform that action at this time.
0 commit comments