File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -3417,3 +3417,53 @@ _:b0 <ex:p> "v" .
34173417 } ) ;
34183418 } ) ;
34193419} ) ;
3420+
3421+ describe ( 'safe canonize defaults' , ( ) => {
3422+ it ( 'does not throw on safe input' , async ( ) => {
3423+ const input =
3424+ {
3425+ "@id" : "ex:id" ,
3426+ "ex:p" : "v"
3427+ }
3428+ ;
3429+ const expected =
3430+ '<ex:id> <ex:p> "v" .\n'
3431+ ;
3432+ const result = await jsonld . canonize ( input ) ;
3433+ assert . deepStrictEqual ( result , expected ) ;
3434+ } ) ;
3435+
3436+ it ( 'throws on unsafe input' , async ( ) => {
3437+ const input =
3438+ {
3439+ "@id" : "ex:id" ,
3440+ "ex:p" : "v" ,
3441+ "unknown" : "error"
3442+ }
3443+ ;
3444+ let error ;
3445+ try {
3446+ await jsonld . canonize ( input ) ;
3447+ } catch ( e ) {
3448+ error = e ;
3449+ }
3450+ assert ( error , 'missing safe validation error' ) ;
3451+ } ) ;
3452+
3453+ it ( 'allows override of safe mode' , async ( ) => {
3454+ const input =
3455+ {
3456+ "@id" : "ex:id" ,
3457+ "ex:p" : "v" ,
3458+ "unknown" : "error"
3459+ }
3460+ ;
3461+ const expected =
3462+ '<ex:id> <ex:p> "v" .\n'
3463+ ;
3464+ const result = await jsonld . canonize ( input , {
3465+ safe : false
3466+ } ) ;
3467+ assert . deepStrictEqual ( result , expected ) ;
3468+ } ) ;
3469+ } ) ;
You can’t perform that action at this time.
0 commit comments