From bff93af17e19e0a9435531f2f932ee110a3ddb14 Mon Sep 17 00:00:00 2001 From: "Craig A. Berry" Date: Thu, 30 Mar 2023 09:55:25 -0500 Subject: [PATCH] Handle XML embedded in tilesource JSON The existing check for whether the tilesource data is XML or JSON looks for a tag anywhere in the response content, which incorrectly flags the content as XML in the case where it is really JSON with XML embedded in it. This commit corrects that problem by requiring the tag to occur as the first non-whitespace part of the content. This is basically a poor person's well-formedness check since well-formed XML cannot have non-whitespace content outside of the root node. N.B. While malformed XML content with non-whitespace characters before the first element has been getting identified as XML, it has not been getting parsed correctly. With current parsing infrastructure, the content has been getting replaced by a parsing error message. With more up-to-date parsing infrastructure, it will throw an error. Either way we're not losing anything by failing to identify malformed XML as XML. Addresses issue #2325. --- src/tilesource.js | 2 +- test/data/iiif_2_0_tiled/info.json | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tilesource.js b/src/tilesource.js index bdebebcc..b7782dbe 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -932,7 +932,7 @@ function processResponse( xhr ){ throw new Error( $.getString( "Errors.Status", status, statusText ) ); } - if( responseText.match(/\s*<.*/) ){ + if( responseText.match(/^\s*<.*/) ){ try{ data = ( xhr.responseXML && xhr.responseXML.documentElement ) ? xhr.responseXML : diff --git a/test/data/iiif_2_0_tiled/info.json b/test/data/iiif_2_0_tiled/info.json index d9b56f62..6d5dde5e 100644 --- a/test/data/iiif_2_0_tiled/info.json +++ b/test/data/iiif_2_0_tiled/info.json @@ -18,7 +18,8 @@ "jpg", "png", "gif" - ] + ] } - ] + ], + "xmp": "\n \n \n \n \n 8 8 8\n \n \n \n \n 50\n \n \n \n \n University of Illinois Library\n \n \n \n " }