summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2013-09-04 16:59:30 +0200
committerYorhel <git@yorhel.nl>2013-09-04 16:59:30 +0200
commit49f4741c72498c28806d0064d09850536cb83969 (patch)
tree7942cb7c0b95e3754e1c99334b563f4877c43af5
parent32eea7065c9a4e8af8d318620b338569b96bcb5f (diff)
Normalize white space in attribute value data
-rw-r--r--yxml-states2
-rw-r--r--yxml.c8
-rw-r--r--yxml.c.in6
3 files changed, 14 insertions, 2 deletions
diff --git a/yxml-states b/yxml-states
index eeede4a..0c3bc27 100644
--- a/yxml-states
+++ b/yxml-states
@@ -149,6 +149,6 @@ elem3 '>' selfclose misc2
attr0 Name attrname attr0; SP attrnameend attr1; '=' attrnameend attr2
attr1 SP attr1; '=' attr2
attr2 SP attr2; '\''|'"' $quote attr3
-attr3 AttValue setdata attr3; '&' refstart attr4; $quote elem2
+attr3 AttValue setattrval attr3; '&' refstart attr4; $quote elem2
attr4 Ref ref attr4; '\x3b' refend attr3
diff --git a/yxml.c b/yxml.c
index 6d3f825..cf3726c 100644
--- a/yxml.c
+++ b/yxml.c
@@ -116,6 +116,12 @@ static inline int yxml_setdata(yxml_t *x, unsigned ch) {
}
+static inline int yxml_setattrval(yxml_t *x, unsigned ch) {
+ /* Normalize attribute values according to the XML spec section 3.3.3. */
+ return yxml_setdata(x, ch == 0x9 || ch == 0xa ? 0x20 : ch);
+}
+
+
/* Go to the misc1 or misc2 state, depending on whether a tag has been opened
* previously or not. (This is a hack to work around a limitation in the state
* machine description in yxml-states) */
@@ -339,7 +345,7 @@ yxml_ret_t yxml_parse(yxml_t *x, int _ch) {
break;
case YXMLS_attr3:
if(yxml_isAttValue(ch))
- return yxml_setdata(x, ch);
+ return yxml_setattrval(x, ch);
if(ch == (unsigned char)'&') {
x->state = YXMLS_attr4;
return yxml_refstart(x, ch);
diff --git a/yxml.c.in b/yxml.c.in
index f08b913..c6c2bd0 100644
--- a/yxml.c.in
+++ b/yxml.c.in
@@ -59,6 +59,12 @@ static inline int yxml_setdata(yxml_t *x, unsigned ch) {
}
+static inline int yxml_setattrval(yxml_t *x, unsigned ch) {
+ /* Normalize attribute values according to the XML spec section 3.3.3. */
+ return yxml_setdata(x, ch == 0x9 || ch == 0xa ? 0x20 : ch);
+}
+
+
/* Go to the misc1 or misc2 state, depending on whether a tag has been opened
* previously or not. (This is a hack to work around a limitation in the state
* machine description in yxml-states) */