View Issue Details

IDProjectCategoryView StatusLast Update
0037295FPCPackagespublic2020-07-07 11:51
ReporterPaweł Dmitruk Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Product Version3.2.0 
Summary0037295: [Patch] fcl-xml: SAX XML - Added support for cdata section and comments
DescriptionAdded support for cdata section and comments in SAX_XML.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Paweł Dmitruk

2020-07-03 20:08

reporter  

sax_xml.pp.patch (3,439 bytes)   
--- C:/lazarus/fpc/3.2.0/source/packages/fcl-xml/src/sax_xml.pp	pt. 2012-06-01 21:57:28
+++ C:/paweld_repo/desktop/_testowy/XML strukt fpc sax/sax_xml.pp	pt. 2020-07-03 19:58:06
@@ -33,0 +34,2 @@ type
+    scCData,            // within cdata section
+    scComment,          // within comment
@@ -62 +64 @@ type
-  TXMLNodeType = (ntWhitespace, ntText, ntEntityReference, ntTag);
+  TXMLNodeType = (ntWhitespace, ntText, ntEntityReference, ntTag, ntComment);
@@ -79,0 +82,2 @@ type
+    procedure ReaderComment(Sender: TObject; const ch: PSAXChar;
+      Start, Count: Integer);
@@ -173,0 +178,11 @@ begin
+                if (Buffer[BufferPos]='!') and (Buffer[BufferPos + 1]='[') then 
+                begin
+                  Inc(BufferPos, 8);
+                  EnterNewScannerContext(scCData);
+                end
+                else if (Buffer[BufferPos]='!') and (Buffer[BufferPos + 1]='-') then 
+                begin
+                  Inc(BufferPos, 3);
+                  EnterNewScannerContext(scComment);
+                end
+                else
@@ -193,0 +209,11 @@ begin
+                if (Buffer[BufferPos]='!') and (Buffer[BufferPos + 1]='[') then 
+                begin
+                  Inc(BufferPos, 8);
+                  EnterNewScannerContext(scCData);
+                end
+                else if (Buffer[BufferPos]='!') and (Buffer[BufferPos + 1]='-') then 
+                begin
+                  Inc(BufferPos, 3);
+                  EnterNewScannerContext(scComment);
+                end
+                else
@@ -208,0 +235,11 @@ begin
+                if (Buffer[BufferPos]='!') and (Buffer[BufferPos + 1]='[') then 
+                begin
+                  Inc(BufferPos, 8);
+                  EnterNewScannerContext(scCData);
+                end
+                else if (Buffer[BufferPos]='!') and (Buffer[BufferPos + 1]='-') then 
+                begin
+                  Inc(BufferPos, 3);
+                  EnterNewScannerContext(scComment);
+                end
+                else
@@ -216,0 +254,22 @@ begin
+        scCData:
+          if (Buffer[BufferPos] = ']') and (Buffer[BufferPos + 1]=']') and (Buffer[BufferPos + 2]='>') then 
+          begin
+            Inc(BufferPos, 3);
+            EnterNewScannerContext(scUnknown);
+          end
+          else
+          begin
+            FRawTokenText := FRawTokenText + Buffer[BufferPos];
+            Inc(BufferPos);
+          end;
+        scComment:
+          if (Buffer[BufferPos] = '-') and (Buffer[BufferPos + 1]='-') and (Buffer[BufferPos + 2]='>') then  
+          begin
+            Inc(BufferPos, 3);
+            EnterNewScannerContext(scUnknown);
+          end
+          else
+          begin
+            FRawTokenText := FRawTokenText + Buffer[BufferPos];
+            Inc(BufferPos);
+          end;
@@ -356 +415,2 @@ begin
-    scText:
+    scText,
+    scCData:
@@ -357,0 +418,2 @@ begin
+    scComment:
+      DoComment(PSAXChar(TokenText), 0, Length(TokenText));
@@ -461,0 +524,11 @@ end;
+procedure TXMLToDOMConverter.ReaderComment(Sender: TObject;
+  const ch: PSAXChar; Start, Count: Integer);
+var
+  NodeInfo: TXMLNodeInfo;
+begin
+  NodeInfo := TXMLNodeInfo.Create;
+  NodeInfo.NodeType := ntComment;
+  NodeInfo.DOMNode := FDocument.CreateCommentBuf(ch, Count);
+  FNodeBuffer.Add(NodeInfo);
+end;
+
sax_xml.pp.patch (3,439 bytes)   

Paweł Dmitruk

2020-07-06 20:39

reporter   ~0123787

previous patch is not ok - if the beginning of the cdata or comment section was split into two 'buffers', it geted data incorrectly.

corrected patch in attachement
sax_xml.pp.01.patch (2,485 bytes)   
--- C:/lazarus/fpc/3.2.0/source/packages/fcl-xml/src/sax_xml.pp	pt. 2012-06-01 21:57:28
+++ C:/paweld_repo/desktop/_testowy/XML strukt fpc sax/sax_xml.pp	pon. 2020-07-06 20:29:51
@@ -33,0 +34,2 @@ type
+    scCData,            // within cdata section
+    scComment,          // within comment
@@ -62 +64 @@ type
-  TXMLNodeType = (ntWhitespace, ntText, ntEntityReference, ntTag);
+  TXMLNodeType = (ntWhitespace, ntText, ntEntityReference, ntTag, ntComment);
@@ -79,0 +82,2 @@ type
+    procedure ReaderComment(Sender: TObject; const ch: PSAXChar;
+      Start, Count: Integer);
@@ -216,0 +221,29 @@ begin
+        scCData:
+          if (Length(FRawTokenText) = 0) and (Buffer[BufferPos] = '-') then
+          begin
+            Inc(BufferPos);
+            EnterNewScannerContext(scComment);
+          end
+          else if (Buffer[BufferPos] = '>') and (RightStr(FRawTokenText, 2) = ']]') then
+          begin
+            FRawTokenText := Copy(FRawTokenText, 8, Length(FRawTokenText)-9);  //delete '[CDATA[' and ']]' from text
+            Inc(BufferPos);
+            EnterNewScannerContext(scUnknown);
+          end
+          else
+          begin
+            FRawTokenText := FRawTokenText + Buffer[BufferPos];
+            Inc(BufferPos);
+          end;
+        scComment:
+          if (Buffer[BufferPos] = '>') and (RightStr(FRawTokenText, 2) = '--') then
+          begin
+            FRawTokenText := Copy(FRawTokenText, 2, Length(FRawTokenText)-3);  //delete '-' and '--' from text
+            Inc(BufferPos);
+            EnterNewScannerContext(scUnknown);
+          end
+          else
+          begin
+            FRawTokenText := FRawTokenText + Buffer[BufferPos];
+            Inc(BufferPos);
+          end;
@@ -252,0 +286,5 @@ begin
+            '!':
+              begin
+                Inc(BufferPos);
+                EnterNewScannerContext(scCData);
+              end;
@@ -356 +394,2 @@ begin
-    scText:
+    scText,
+    scCData:
@@ -357,0 +397,2 @@ begin
+    scComment:
+      DoComment(PSAXChar(TokenText), 0, Length(TokenText));
@@ -461,0 +503,11 @@ end;
+procedure TXMLToDOMConverter.ReaderComment(Sender: TObject;
+  const ch: PSAXChar; Start, Count: Integer);
+var
+  NodeInfo: TXMLNodeInfo;
+begin
+  NodeInfo := TXMLNodeInfo.Create;
+  NodeInfo.NodeType := ntComment;
+  NodeInfo.DOMNode := FDocument.CreateCommentBuf(ch, Count);
+  FNodeBuffer.Add(NodeInfo);
+end;
+
sax_xml.pp.01.patch (2,485 bytes)   

Issue History

Date Modified Username Field Change
2020-07-03 20:08 Paweł Dmitruk New Issue
2020-07-03 20:08 Paweł Dmitruk File Added: sax_xml.pp.patch
2020-07-06 20:39 Paweł Dmitruk Note Added: 0123787
2020-07-06 20:39 Paweł Dmitruk File Added: sax_xml.pp.01.patch
2020-07-07 11:51 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-07-07 11:51 Michael Van Canneyt Status new => assigned