[glib: 1/2] gmarkup tests: tab character escape/unescape



commit 50a3064933ab781f13c2691aeffd3b183e3e121d
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Mar 31 16:53:02 2020 +0200

    gmarkup tests: tab character escape/unescape
    
    "\t" is not escaped by g_markup_escape_text(), as per its documentation:
    
    "Note that this function doesn't protect whitespace and line endings
    from being processed according to the XML rules for normalization of
    line endings and attribute values."
    
    The relevant portion of the XML specification
    https://www.w3.org/TR/xml/#AVNormalize
    
    "For a character reference, append the referenced character to the
    normalized value."
    "For a white space character (#x20, #xD, #xA, #x9), append a space
    character (#x20) to the normalized value."
    
    So the unescape code in GMarkup does the right thing as can be verified
    by the added valid-17.* data files for the markup-parse unit test.
    
    (Note that the valid-13.* data files already tested a plain tab
    character in an attribute value, among other white space characters).
    
    Note that the libxml2's xmlSetProp() function escapes "\t" into the
    character reference "&#9;".
    
    See https://gitlab.gnome.org/GNOME/glib/-/issues/2080

 glib/tests/markup-escape.c           | 3 +++
 glib/tests/markups/valid-17.expected | 6 ++++++
 glib/tests/markups/valid-17.gmarkup  | 2 ++
 3 files changed, 11 insertions(+)
---
diff --git a/glib/tests/markup-escape.c b/glib/tests/markup-escape.c
index 7ec4df926..2d5de854d 100644
--- a/glib/tests/markup-escape.c
+++ b/glib/tests/markup-escape.c
@@ -37,6 +37,9 @@ static EscapeTest escape_tests[] =
   { "N\xc2\x80N", "N&#x80;N" },
   { "N\xc2\x79N", "N\xc2\x79N" },
   { "N\xc2\x9fN", "N&#x9f;N" },
+
+  /* As per g_markup_escape_text()'s documentation, whitespace is not escaped: */
+  { "\t", "\t" },
 };
 
 static void
diff --git a/glib/tests/markups/valid-17.expected b/glib/tests/markups/valid-17.expected
new file mode 100644
index 000000000..b042f4de7
--- /dev/null
+++ b/glib/tests/markups/valid-17.expected
@@ -0,0 +1,6 @@
+ELEMENT 'foo'
+tab=" "
+END 'foo'
+ELEMENT 'bar'
+tab_character_reference="      "
+END 'bar'
diff --git a/glib/tests/markups/valid-17.gmarkup b/glib/tests/markups/valid-17.gmarkup
new file mode 100644
index 000000000..255b2f4fe
--- /dev/null
+++ b/glib/tests/markups/valid-17.gmarkup
@@ -0,0 +1,2 @@
+<foo tab="     " />
+<bar tab_character_reference="&#9;" />


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]