@@ -36,7 +36,10 @@ const isInteger = (schema: TAnySchema) => {
3636 continue
3737 }
3838
39- if ( ! hasNumberType && ( type . type === 'number' || type . type === 'integer' ) ) {
39+ if (
40+ ! hasNumberType &&
41+ ( type . type === 'number' || type . type === 'integer' )
42+ ) {
4043 hasNumberType = true
4144 continue
4245 }
@@ -257,7 +260,7 @@ const accelerate = (
257260
258261 switch ( schema . type ) {
259262 case 'string' :
260- instruction . hasString = true
263+ if ( ! schema . const && ! schema . trusted ) instruction . hasString = true
261264
262265 // string operation would be repeated multiple time
263266 // it's fine to optimize it to the most optimized way
@@ -272,10 +275,19 @@ const accelerate = (
272275 // this handle the case where the string contains double quotes
273276 // As slice(1,-1) is use several compute and would be called multiple times
274277 // it's not ideal to slice(1, -1) of JSON.stringify
275- if ( nullableCondition )
278+ if ( nullableCondition ) {
279+ if ( schema . trusted )
280+ sanitize = ( v : string ) =>
281+ `\`"$\{${ SANITIZE [ 'manual' ] ( v ) } }"\``
282+
276283 v = `\${${ nullableCondition } ?${ schema . const !== undefined ? `'${ JSON . stringify ( schema . const ) } '` : schema . default !== undefined ? `'${ JSON . stringify ( schema . default ) } '` : `'null'` } :${ sanitize ( property ) } }`
277- else
278- v = `${ schema . const !== undefined ? `${ JSON . stringify ( schema . const ) } ` : `\${${ sanitize ( property ) } }` } `
284+ } else {
285+ if ( schema . const !== undefined )
286+ v = JSON . stringify ( schema . const )
287+ else if ( schema . trusted )
288+ v = `"\${${ SANITIZE [ 'manual' ] ( property ) } }"`
289+ else v = `\${${ sanitize ( property ) } }`
290+ }
279291 } else {
280292 // In this case quote is handle outside to improve performance
281293 if ( nullableCondition )
0 commit comments