File tree 3 files changed +22
-0
lines changed
3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import {
26
26
removeNewLinesAndExtraSpaces ,
27
27
toFixedLocale ,
28
28
} from "./str" ;
29
+ import { containsEncodedComponents } from "./url" ;
29
30
import { getUUID } from "./uuid" ;
30
31
31
32
export {
@@ -57,4 +58,5 @@ export {
57
58
toFixedLocale ,
58
59
getUUID ,
59
60
getSearchQuerySelector ,
61
+ containsEncodedComponents ,
60
62
} ;
Original file line number Diff line number Diff line change
1
+ /** Check whether URL component is encoded already.
2
+ * @see [MDN]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent}
3
+ * @param {String } x
4
+ * @returns {boolean }
5
+ */
6
+ export function containsEncodedComponents ( x ) {
7
+ // ie ?,=,&,/ etc
8
+ return decodeURI ( x ) !== decodeURIComponent ( x ) ;
9
+ }
Original file line number Diff line number Diff line change 1
1
import { expect } from "chai" ;
2
2
3
3
import { deepClone } from "../src/utils/clone" ;
4
+ import { containsEncodedComponents } from "../src/utils/url" ;
4
5
5
6
describe ( "deepClone" , ( ) => {
6
7
const obj = {
@@ -22,3 +23,13 @@ describe("deepClone", () => {
22
23
expect ( other ) . not . to . haveOwnProperty ( "object" ) ;
23
24
} ) ;
24
25
} ) ;
26
+
27
+ describe ( "containsEncodedComponents" , ( ) => {
28
+ const decodedComponent = "a test with // special = characters?" ;
29
+ const encodedComponent = encodeURIComponent ( decodedComponent ) ;
30
+
31
+ it ( "identifies whether a string is URL encoded" , ( ) => {
32
+ expect ( containsEncodedComponents ( encodedComponent ) ) . to . be . true ;
33
+ expect ( containsEncodedComponents ( decodedComponent ) ) . to . be . false ;
34
+ } ) ;
35
+ } ) ;
You can’t perform that action at this time.
0 commit comments