Skip to content

Commit

Permalink
fix: Ignore trailing '#' in meta-schema URLs (#497)
Browse files Browse the repository at this point in the history
A single trailing # should be present for draft-07 and earlier, but should not be present for 2019-09 or 2020-12. But for simplicity and robustness, we can just ignore it in all cases
  • Loading branch information
GREsau authored Sep 10, 2024
1 parent f001fe6 commit 9c12d24
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions jsonschema/src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ impl Draft {
/// Get the `Draft` from a JSON Schema URL.
#[inline]
pub(crate) fn draft_from_url(url: &str) -> Option<Draft> {
match url {
match url.trim_end_matches('#') {
#[cfg(feature = "draft202012")]
"https://json-schema.org/draft/2020-12/schema#" => Some(Draft::Draft202012),
"https://json-schema.org/draft/2020-12/schema" => Some(Draft::Draft202012),
#[cfg(feature = "draft201909")]
"https://json-schema.org/draft/2019-09/schema#" => Some(Draft::Draft201909),
"http://json-schema.org/draft-07/schema#" => Some(Draft::Draft7),
"http://json-schema.org/draft-06/schema#" => Some(Draft::Draft6),
"http://json-schema.org/draft-04/schema#" => Some(Draft::Draft4),
"https://json-schema.org/draft/2019-09/schema" => Some(Draft::Draft201909),
"http://json-schema.org/draft-07/schema" => Some(Draft::Draft7),
"http://json-schema.org/draft-06/schema" => Some(Draft::Draft6),
"http://json-schema.org/draft-04/schema" => Some(Draft::Draft4),
_ => None,
}
}
Expand Down Expand Up @@ -225,8 +225,8 @@ mod tests {
use serde_json::{json, Value};
use test_case::test_case;

#[cfg_attr(feature = "draft201909", test_case(&json!({"$schema": "https://json-schema.org/draft/2019-09/schema#"}), Some(Draft::Draft201909)))]
#[cfg_attr(feature = "draft202012", test_case(&json!({"$schema": "https://json-schema.org/draft/2020-12/schema#"}), Some(Draft::Draft202012)))]
#[cfg_attr(feature = "draft201909", test_case(&json!({"$schema": "https://json-schema.org/draft/2019-09/schema"}), Some(Draft::Draft201909)))]
#[cfg_attr(feature = "draft202012", test_case(&json!({"$schema": "https://json-schema.org/draft/2020-12/schema"}), Some(Draft::Draft202012)))]
#[test_case(&json!({"$schema": "http://json-schema.org/draft-07/schema#"}), Some(Draft::Draft7))]
#[test_case(&json!({"$schema": "http://json-schema.org/draft-06/schema#"}), Some(Draft::Draft6))]
#[test_case(&json!({"$schema": "http://json-schema.org/draft-04/schema#"}), Some(Draft::Draft4))]
Expand Down

0 comments on commit 9c12d24

Please sign in to comment.