]> mj.ucw.cz Git - libucw.git/commitdiff
XML: Bugfix in processing of multi-byte newlines.
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Wed, 23 Apr 2008 13:40:06 +0000 (15:40 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Wed, 23 Apr 2008 13:40:06 +0000 (15:40 +0200)
sherlock/xml/source.c
sherlock/xml/xml.h

index 657268df3f07e4a765243ad29eb042dfada0e6b4..3b06f510b41c7b9a896969a3963d9662dfac05ee 100644 (file)
@@ -80,7 +80,7 @@ xml_push_source(struct xml_context *ctx)
   src->next = ctx->src;
   src->saved_depth = ctx->depth;
   ctx->src = src;
-  ctx->flags &= ~(XML_SRC_EOF | XML_SRC_EXPECTED_DECL | XML_SRC_NEW_LINE | XML_SRC_DOCUMENT);
+  ctx->flags &= ~(XML_SRC_EOF | XML_SRC_EXPECTED_DECL | XML_SRC_DOCUMENT);
   ctx->bstop = ctx->bptr = src->buf;
   ctx->depth = 0;
   return src;
@@ -182,9 +182,9 @@ void xml_parse_decl(struct xml_context *ctx);
   struct fastbuf *fb = src->fb;                                                                \
   if (ctx->bptr == ctx->bstop)                                                         \
     ctx->bptr = ctx->bstop = src->buf;                                                 \
-  uns f = ctx->flags, c, t1 = src->refill_cat1, t2 = src->refill_cat2, row = src->row; \
+  uns c, t1 = src->refill_cat1, t2 = src->refill_cat2, row = src->row;         \
   u32 *bend = src->buf + ARRAY_SIZE(src->buf), *bstop = ctx->bstop,                    \
-      *last_0xd = (f & XML_SRC_NEW_LINE) ? bstop : bend;                               \
+      *last_0xd = src->pending_0xd ? bstop : NULL;                                     \
   do                                                                                   \
     {                                                                                  \
       c = func(fb, ##params);                                                          \
@@ -201,7 +201,7 @@ void xml_parse_decl(struct xml_context *ctx);
            last_0xd = bstop + 2;                                                       \
          else if (c != 0x2028 && last_0xd == bstop)                                    \
            {                                                                           \
-             last_0xd = bend;                                                          \
+             last_0xd = NULL;                                                          \
              continue;                                                                 \
            }                                                                           \
          xml_add_char(&bstop, 0xa), row++;                                             \
@@ -218,12 +218,12 @@ void xml_parse_decl(struct xml_context *ctx);
       else                                                                             \
         {                                                                              \
          /* EOF */                                                                     \
-          f |= XML_SRC_EOF;                                                            \
+          ctx->flags |= XML_SRC_EOF;                                                   \
           break;                                                                       \
        }                                                                               \
     }                                                                                  \
   while (bstop < bend);                                                                        \
-  ctx->flags = (last_0xd == bstop) ? f | XML_SRC_NEW_LINE : f & ~XML_SRC_NEW_LINE;     \
+  src->pending_0xd = (last_0xd == bstop);                                              \
   ctx->bstop = bstop;                                                                  \
   src->row = row;
 
index 6a327ec1bd56c886e896da0a76360681bb0c4352..ac9ebefb70f8a88ab6f1056326dd876eb0e44002 100644 (file)
@@ -88,9 +88,8 @@ enum xml_flags {
   XML_HAS_INTERNAL_SUBSET =            0x00080000,     /* The document contains an internal subset */
   XML_SRC_EOF =                                0x00100000,     /* EOF reached */
   XML_SRC_EXPECTED_DECL =              0x00200000,     /* Just before optional or required XMLDecl/TextDecl */
-  XML_SRC_NEW_LINE =                   0x00400000,     /* The last read character is 0xD */
-  XML_SRC_DOCUMENT =                   0x00800000,     /* The document entity */
-  XML_SRC_EXTERNAL =                   0x01000000,     /* An external entity */
+  XML_SRC_DOCUMENT =                   0x00400000,     /* The document entity */
+  XML_SRC_EXTERNAL =                   0x00800000,     /* An external entity */
 };
 
 enum xml_node_type {
@@ -150,6 +149,7 @@ struct xml_source {
   void (*refill)(struct xml_context *ctx);             /* Callback to decode source characters to the buffer */
   unsigned short *refill_in_to_x;                      /* Libcharset input table */
   uns saved_depth;                                     /* Saved ctx->depth */
+  uns pending_0xd;                                     /* The last read character is 0xD */
 };
 
 struct xml_context {