FPSpreadsheet: Fix writing of meta data containing special xml characters (sourceforge issue #46)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7894 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2020-11-21 11:33:02 +00:00
parent db8138802d
commit 35fecc8c8d
5 changed files with 22 additions and 21 deletions

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<Version Value="11"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="demo_metadata"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
@ -24,6 +24,7 @@
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<RequiredPackages Count="1">
<Item1>

View File

@ -62,17 +62,17 @@ var
begin
book := TsWorkbook.Create;
try
book.MetaData.CreatedBy := 'Donald Duck';
book.MetaData.CreatedBy := 'Donald Duck & Dagobert Duck';
book.MetaData.Authors.Add('Donald Duck II');
book.MetaData.DateCreated := EncodeDate(2020, 1, 1) + EncodeTime(12, 30, 40, 20);
book.MetaData.DateLastModified := Now();
book.MetaData.LastModifiedBy := 'Dagobert Duck';
book.MetaData.Title := 'Test of metadata äöü';
book.Metadata.Subject := 'FPSpreadsheet demos';
book.Metadata.Subject := 'FPSpreadsheet demos & tests';
book.MetaData.Comments.Add('This is a test of spreadsheet metadata.');
book.MetaData.Comments.Add('Assign the author to the field CreatedBy.');
book.MetaData.Comments.Add('Assign the creation date to the field CreatedAt.');
book.MetaData.Keywords.Add('Test1,Test2');
book.MetaData.Keywords.Add('Test1,Test2,Test3&4');
book.MetaData.Keywords.Add('FPSpreadsheet');
book.MetaData.AddCustom('Comparny', 'Disney');
book.MetaData.AddCustom('Status', 'finished');

View File

@ -5877,23 +5877,23 @@ begin
begin
s := book.Metadata.Title;
AppendToStream(FSMeta, Format(
'<dc:title>%s</dc:title>', [s]));
'<dc:title>%s</dc:title>', [UTF8TextToXMLText(s)]));
end;
if book.Metadata.Subject <> '' then
begin
s := book.Metadata.Subject;
AppendToStream(FSMeta, Format(
'<dc:subject>%s</dc:subject>', [s]));
'<dc:subject>%s</dc:subject>', [UTF8TextToXMLText(s)]));
end;
if book.Metadata.CreatedBy <> '' then
AppendToStream(FSMeta, Format(
'<meta:initial-creator>%s</meta:initial-creator>', [book.MetaData.CreatedBy]));
'<meta:initial-creator>%s</meta:initial-creator>', [UTF8TextToXMLText(book.MetaData.CreatedBy)]));
if book.MetaData.LastModifiedBy <> '' then
AppendToStream(FSMeta, Format(
'<dc:creator>%s</dc:creator>', [book.Metadata.LastModifiedBy]));
'<dc:creator>%s</dc:creator>', [UTF8TextToXMLText(book.Metadata.LastModifiedBy)]));
if book.MetaData.DateCreated > 0 then
begin
@ -5914,7 +5914,7 @@ begin
if book.MetaData.Keywords.Count > 0 then
for i := 0 to book.MetaData.Keywords.Count-1 do
AppendToStream(FSMeta, Format(
'<meta:keyword>%s</meta:keyword>', [book.MetaData.Keywords[i]]));
'<meta:keyword>%s</meta:keyword>', [UTF8TextToXMLText(book.MetaData.Keywords[i])]));
if book.MetaData.Comments.Count > 0 then
begin
@ -5922,7 +5922,7 @@ begin
for i := 1 to book.MetaData.Comments.Count-1 do
s := s + #10 + book.MetaData.Comments[i];
AppendToStream(FSMeta, Format(
'<dc:description>%s</dc:description>', [s]));
'<dc:description>%s</dc:description>', [UTF8TextToXMLText(s)]));
end;
if book.MetaData.Custom.Count > 0 then
@ -5931,7 +5931,7 @@ begin
AppendToStream(FSMeta, Format(
'<meta:user-defined meta:name="%s">%s</meta:user-defined>', [
book.Metadata.Custom.Names[i],
book.Metadata.Custom.ValueFromIndex[i]
UTF8TextToXMLText(book.Metadata.Custom.ValueFromIndex[i])
]));
end;

View File

@ -2729,7 +2729,7 @@ begin
AppendToStream(AStream, Format(INDENT2 +
'<%0:s dt:dt="string">%1:s</%0:s>' + LF, [
book.MetaData.Custom.Names[i],
book.MetaData.Custom.ValueFromIndex[i]
UTF8TextToXMLText(book.MetaData.Custom.ValueFromIndex[i])
]));
AppendToStream(AStream, INDENT1 +
@ -2795,22 +2795,22 @@ begin
end;
if book.MetaData.Title <> '' then
sTitle := '<Title>' + book.MetaData.Title + '</Title>' + LF + INDENT2
sTitle := '<Title>' + UTF8TextToXMLText(book.MetaData.Title) + '</Title>' + LF + INDENT2
else
sTitle := '';
if book.MetaData.Subject <> '' then
sSubject := '<Subject>' + book.MetaData.Subject + '</Subject>' + LF + INDENT2
sSubject := '<Subject>' + UTF8TextToXMLText(book.MetaData.Subject) + '</Subject>' + LF + INDENT2
else
sSubject := '';
if book.MetaData.CreatedBy <> '' then
sAuthor := '<Author>' + book.MetaData.CreatedBy + '</Author>' + LF + INDENT2
sAuthor := '<Author>' + UTF8TextToXMLText(book.MetaData.CreatedBy) + '</Author>' + LF + INDENT2
else
sAuthor := '';
if book.MetaData.LastModifiedBy <> '' then
sLastAuthor := '<LastAuthor>' + book.MetaData.LastModifiedBy + '</LastAuthor>' + LF + INDENT2
sLastAuthor := '<LastAuthor>' + UTF8TextToXMLText(book.MetaData.LastModifiedBy) + '</LastAuthor>' + LF + INDENT2
else
sLastAuthor := '';

View File

@ -6288,7 +6288,7 @@ begin
begin
s := book.MetaData.KeyWords.CommaText;
AppendToStream(AStream, Format(
'<cp:keywords>%s</cp:keywords>', [s]));
'<cp:keywords>%s</cp:keywords>', [UTF8TextToXMLText(s)]));
end;
if book.MetaData.Comments.Count > 0 then
@ -6298,14 +6298,14 @@ begin
Delete(s, Length(s), 1);
s := StringReplace(s, LineEnding, '_x000d_', [rfReplaceAll]);
AppendToStream(AStream, Format(
'<dc:description>%s</dc:description>', [s]));
'<dc:description>%s</dc:description>', [UTF8TextToXMLText(s)]));
end;
if book.MetaData.LastModifiedBy <> '' then
begin
s := book.MetaData.LastModifiedBy;
AppendToStream(AStream, Format(
'<cp:lastModifiedBy>%s</cp:lastModifiedBy>', [s])); // to do: check xml entities
'<cp:lastModifiedBy>%s</cp:lastModifiedBy>', [UTF8TextToXMLText(s)]));
end;
if book.MetaData.DateCreated > 0 then
@ -6313,7 +6313,7 @@ begin
dt := book.MetaData.DateCreated + GetLocalTimeOffset / MinsPerDay;
s := FormatDateTime(ISO8601FormatExtendedUTC, dt);
AppendToStream(AStream, Format(
'<dcterms:created xsi:type="dcterms:W3CDTF">%s</dcterms:created>', [s]));
'<dcterms:created xsi:type="dcterms:W3CDTF">%s</dcterms:created>', [UTF8TextToXMLText(s)]));
end;
if book.MetaData.DateLastModified >0 then