File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 22
33## [ Unreleased]
44
5+ ### Fixed
6+
7+ - Stack overflow on empty ` $ref ` value. [ #886 ] ( https://github.com/Stranger6667/jsonschema/issues/886 )
8+
59## [ 0.37.0] - 2025-11-19
610
711### Added
Original file line number Diff line number Diff line change 22
33## [ Unreleased]
44
5+ ### Fixed
6+
7+ - Stack overflow on empty ` $ref ` value. [ #886 ] ( https://github.com/Stranger6667/jsonschema/issues/886 )
8+
59## [ 0.37.0] - 2025-11-19
610
711### Added
Original file line number Diff line number Diff line change @@ -21,8 +21,11 @@ fn compile_reference_validator<'a>(
2121 Err ( error) => return Some ( Err ( error) ) ,
2222 } ;
2323
24- if alias == current_location {
24+ if alias == current_location
25+ || ( reference. is_empty ( ) && alias. strip_fragment ( ) == current_location. strip_fragment ( ) )
26+ {
2527 // Direct self-reference would recurse indefinitely, treat it as an annotation-only schema.
28+ // Empty string $ref ("") is a same-document reference per RFC 3986, equivalent to "#"
2629 return None ;
2730 }
2831
@@ -573,4 +576,15 @@ mod tests {
573576 "Resource './virtualNetwork.json' is not present in a registry and retrieving it failed: No base URI is available"
574577 ) ;
575578 }
579+
580+ #[ test]
581+ fn test_empty_ref_no_stack_overflow ( ) {
582+ // Empty string is a same-document reference per RFC 3986, should behave like $ref: "#"
583+ let schema = json ! ( { "$ref" : "" } ) ;
584+ let instance = json ! ( -1 ) ;
585+
586+ // Should compile without error and validate without stack overflow
587+ let validator = crate :: validator_for ( & schema) . expect ( "Should compile" ) ;
588+ assert ! ( validator. is_valid( & instance) ) ;
589+ }
576590}
You can’t perform that action at this time.
0 commit comments