Skip to content

Commit

Permalink
Merge branch 'master' into yaml-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
big-andy-coates authored Jan 25, 2024
2 parents 3253521 + dad215d commit b45667f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
8 changes: 4 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ test {

dependencies {
implementation 'com.damnhandy:handy-uri-templates:2.1.8'
implementation 'com.ibm.icu:icu4j:69.1'
implementation 'com.ibm.icu:icu4j:74.2'
implementation 'commons-validator:commons-validator:1.7'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.5'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.16.1'
implementation 'org.jruby.joni:joni:2.1.41'
implementation 'org.jsoup:jsoup:1.14.2'
implementation 'org.jsoup:jsoup:1.17.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.0'
testImplementation 'org.json:json:20210307'
testImplementation 'org.json:json:20231013'
testImplementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,42 +150,46 @@ public Schema loadSchema(URI uri, Validator validator, Consumer<ValidationError>
uri = validUriToCanonicalUri.get(uri);
continue;
}
if (!canonicalUriToObject.containsKey(uri) && uri.isAbsolute()) {
// We don't know this canonical URL, so we treat it as a resource URL and try to fetch
// it.
URI documentUri = baseDocumentFromUri(uri);
LOG.fine("Loading: " + documentUri + " to resolve: " + uri);

try {
if (!mapped.contains(documentUri)) {
String content = getContent(documentUri);
try {
store(documentUri, new ObjectMapper().readValue(content, Object.class));
} catch (JsonProcessingException e) {
// This is a special method designed to handle the JavaScript-based redirection (not
// http) on the web page at http://json-schema.org/schema.
// If the loaded content is an HTML page with a canonical reference to another
// destination. we make a one-off attempt to fetch the document at that destination.
Document doc = Jsoup.parse(content);
Elements links = doc.head().select("link[rel='canonical']");
boolean resolved = false;
for (Element link : links) {
String href = link.attr("href");
URI canonical = new URL(documentUri.toURL(), href).toURI();
if (!canonical.equals(documentUri)) {
store(documentUri, getContent(canonical));
resolved = true;
break;
if (uri.isAbsolute()){
// for uri with #fragment try to fetch the base document if not loaded already
URI documentUri = baseDocumentFromUri(uri);
if (!canonicalUriToObject.containsKey(documentUri)){
// We don't know this canonical URL, so we treat it as a resource URL and try to fetch
// it.
LOG.fine("Loading: " + documentUri + " to resolve: " + uri);

try{
if (!mapped.contains(documentUri)){
String content = getContent(documentUri);
try{
store(documentUri, new ObjectMapper().readValue(content, Object.class));
}catch (JsonProcessingException e){
// This is a special method designed to handle the JavaScript-based redirection (not
// http) on the web page at http://json-schema.org/schema.
// If the loaded content is an HTML page with a canonical reference to another
// destination. we make a one-off attempt to fetch the document at that destination.
Document doc = Jsoup.parse(content);
Elements links = doc.head().select("link[rel='canonical']");
boolean resolved = false;
for (Element link : links){
String href = link.attr("href");
URI canonical = new URL(documentUri.toURL(), href).toURI();
if (!canonical.equals(documentUri)){
store(documentUri, getContent(canonical));
resolved = true;
break;
}
}
if (!resolved){
LOG.warning("Was not valid JSON: " + documentUri);
}
}
if (!resolved) {
LOG.warning("Was not valid JSON: " + uri);
}
continue;
}
continue;
}catch (IOException | URISyntaxException e){
LOG.warning("Failed attempt to auto fetch " + documentUri + " to resolve: " + uri);
}
} catch (IOException | URISyntaxException e) {
LOG.warning("Failed attempt to auto fetch to resolve: " + uri);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static Collection<DynamicNode> scan(Set<Path> testDirs, Path remotes, UR
URI testSourceUri =
ResourceUtils.getResource(SuiteTest.class, resourcePath.toString()).toURI();
Path allowListFolder =
FILE_SYSTEM.getPath(path.toString().replaceFirst("/suites/", "suiteAllowList/"));
FILE_SYSTEM.getPath(path.toString().replaceFirst("[/\\\\]suites[/\\\\]", "suiteAllowList/"));
Path allowListFile = allowListFolder.resolve(resource);

InputStream allowListInStream = getResourceAsStream(SuiteTest.class, "/" + allowListFile);
Expand Down

0 comments on commit b45667f

Please sign in to comment.