From e83c016c695a6eae3537322142ac39ef1410f971 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Thu, 15 Oct 2020 21:56:23 -0400 Subject: [PATCH] strict context went out of bounds --- dom.d | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dom.d b/dom.d index 8c2ebb7..0bb8f15 100644 --- a/dom.d +++ b/dom.d @@ -843,9 +843,11 @@ class Document : FileResource { selfClosed = true; } - if(strict) - enforce(data[pos] == '>', format("got %s when expecting > (possible missing attribute name)\nContext:\n%s", data[pos], data[pos - 100 .. pos + 100])); - else { + import std.algorithm.comparison; + + if(strict) { + enforce(data[pos] == '>', format("got %s when expecting > (possible missing attribute name)\nContext:\n%s", data[pos], data[max(0, pos - 100) .. min(data.length, pos + 100)])); + } else { // if we got here, it's probably because a slash was in an // unquoted attribute - don't trust the selfClosed value if(!selfClosed) @@ -8893,6 +8895,14 @@ immutable string html = q{ assert(rd.href == "/reviews/8832"); } +unittest { + try { + auto doc = new XmlDocument(""); + } catch(Exception e) { + // good; it should throw an exception, not an error. + } +} + /* Copyright: Adam D. Ruppe, 2010 - 2020 License: Boost License 1.0.