File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use strict' ;
2- const SafeString = require ( 'handlebars' ) . SafeString ;
2+ const common = require ( './lib/common.js' ) ;
33
44const factory = ( ) => {
55 return function ( data ) {
6- if ( data instanceof SafeString ) {
7- data = data . toString ( ) ;
8- }
6+ data = common . unwrapIfSafeString ( data ) ;
97 return JSON . stringify ( data ) ;
108 } ;
119} ;
Original file line number Diff line number Diff line change 11'use strict' ;
22const URL = require ( 'url' ) . URL ;
3+ const SafeString = require ( 'handlebars' ) . SafeString ;
34
45function isValidURL ( val ) {
56 try {
@@ -10,6 +11,14 @@ function isValidURL(val) {
1011 }
1112}
1213
14+ function unwrapIfSafeString ( val ) {
15+ if ( val instanceof SafeString ) {
16+ val = val . toString ( ) ;
17+ }
18+ return val ;
19+ }
20+
1321module . exports = {
1422 isValidURL,
23+ unwrapIfSafeString
1524} ;
Original file line number Diff line number Diff line change @@ -6,15 +6,9 @@ const SafeString = require('handlebars').SafeString;
66
77const factory = ( ) => {
88 return function ( string , key , value ) {
9- if ( string instanceof SafeString ) {
10- string = string . toString ( ) ;
11- }
12- if ( key instanceof SafeString ) {
13- key = key . toString ( ) ;
14- }
15- if ( value instanceof SafeString ) {
16- value = value . toString ( ) ;
17- }
9+ string = common . unwrapIfSafeString ( string ) ;
10+ key = common . unwrapIfSafeString ( key ) ;
11+ value = common . unwrapIfSafeString ( value ) ;
1812 if ( ! utils . isString ( string ) || ! common . isValidURL ( string ) ) {
1913 throw new TypeError ( "Invalid URL passed to setURLQueryParam" ) ;
2014 } else if ( ! utils . isString ( key ) ) {
Original file line number Diff line number Diff line change 11'use strict' ;
2- const SafeString = require ( 'handlebars' ) . SafeString ;
32const utils = require ( 'handlebars-utils' ) ;
3+ const common = require ( './lib/common.js' ) ;
44
55const factory = ( ) => {
66 return function ( url ) {
7- if ( url instanceof SafeString ) {
8- url = url . toString ( ) ;
9- }
7+ url = common . unwrapIfSafeString ( url ) ;
108 if ( utils . isString ( url ) ) {
119 return url . split ( '?' ) [ 0 ] ;
1210 }
You can’t perform that action at this time.
0 commit comments