Skip to content

Commit 4897027

Browse files
committed
Catch URIErrors from URL helper functions.
1 parent 5d3106e commit 4897027

File tree

6 files changed

+90
-5
lines changed

6 files changed

+90
-5
lines changed

src/functions.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,19 @@ const functions = (() => {
591591
return undefined;
592592
}
593593

594-
return encodeURIComponent(str);
594+
// Catch URIErrors when URI sequence is malformed
595+
var returnVal;
596+
try {
597+
returnVal = encodeURIComponent(str);
598+
} catch (e) {
599+
throw {
600+
code: "D3140",
601+
stack: (new Error()).stack,
602+
value: str,
603+
functionName: "encodeUrlComponent"
604+
};
605+
}
606+
return returnVal;
595607
}
596608

597609
/**
@@ -605,7 +617,19 @@ const functions = (() => {
605617
return undefined;
606618
}
607619

608-
return encodeURI(str);
620+
// Catch URIErrors when URI sequence is malformed
621+
var returnVal;
622+
try {
623+
returnVal = encodeURI(str);
624+
} catch (e) {
625+
throw {
626+
code: "D3140",
627+
stack: (new Error()).stack,
628+
value: str,
629+
functionName: "encodeUrl"
630+
};
631+
}
632+
return returnVal;
609633
}
610634

611635
/**
@@ -619,7 +643,19 @@ const functions = (() => {
619643
return undefined;
620644
}
621645

622-
return decodeURIComponent(str);
646+
// Catch URIErrors when URI sequence is malformed
647+
var returnVal;
648+
try {
649+
returnVal = decodeURIComponent(str);
650+
} catch (e) {
651+
throw {
652+
code: "D3140",
653+
stack: (new Error()).stack,
654+
value: str,
655+
functionName: "decodeUrlComponent"
656+
};
657+
}
658+
return returnVal;
623659
}
624660

625661
/**
@@ -633,7 +669,19 @@ const functions = (() => {
633669
return undefined;
634670
}
635671

636-
return decodeURI(str);
672+
// Catch URIErrors when URI sequence is malformed
673+
var returnVal;
674+
try {
675+
returnVal = decodeURI(str);
676+
} catch (e) {
677+
throw {
678+
code: "D3140",
679+
stack: (new Error()).stack,
680+
value: str,
681+
functionName: "decodeUrl"
682+
};
683+
}
684+
return returnVal;
637685
}
638686

639687
/**

src/jsonata.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,8 @@ var jsonata = (function() {
18181818
"D3136": "The date/time picture string is missing specifiers required to parse the timestamp",
18191819
"D3137": "{{{message}}}",
18201820
"D3138": "The $single() function expected exactly 1 matching result. Instead it matched more.",
1821-
"D3139": "The $single() function expected exactly 1 matching result. Instead it matched 0."
1821+
"D3139": "The $single() function expected exactly 1 matching result. Instead it matched 0.",
1822+
"D3140": "Malformed URL passed to ${{{functionName}}}(): {{value}}"
18221823
};
18231824

18241825
/**
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"expr": "$decodeUrl('%E0%A4%A')",
3+
"dataset": "dataset5",
4+
"bindings": {},
5+
"error": {
6+
"code": "D3140",
7+
"message": "Malformed URL passed to $decodeUrl(): \"%E0%A4%A\""
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"expr": "$decodeUrlComponent('%E0%A4%A')",
3+
"dataset": "dataset5",
4+
"bindings": {},
5+
"error": {
6+
"code": "D3140",
7+
"message": "Malformed URL passed to $decodeUrlComponent(): \"%E0%A4%A\""
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"expr": "$encodeUrl('\uD800')",
3+
"dataset": "dataset5",
4+
"bindings": {},
5+
"error": {
6+
"code": "D3140",
7+
"message": "Malformed URL passed to $encodeUrl(): \"\uD800\""
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"expr": "$encodeUrlComponent('\uD800')",
3+
"dataset": "dataset5",
4+
"bindings": {},
5+
"error": {
6+
"code": "D3140",
7+
"message": "Malformed URL passed to $encodeUrlComponent(): \"\uD800\""
8+
}
9+
}

0 commit comments

Comments
 (0)