summaryrefslogtreecommitdiff
path: root/sax/source
diff options
context:
space:
mode:
authordante <dante19031999@gmail.com>2020-12-02 00:02:45 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-12-07 13:28:52 +0100
commit1a6191621a0257c479bdfe24e125c0258d4b3d0d (patch)
treea43671e43776598ced8926500a61c72f82382565 /sax/source
parentf319d6b543c2367546bc80d138e56ed03731e265 (diff)
Adding suppor for &#dddd; and &#xhhhh; on fastparser.
Change-Id: Iacbbe8a77532fe5034ceae286f50a74310f7d2ed Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107036 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sax/source')
-rw-r--r--sax/source/fastparser/fastparser.cxx39
1 files changed, 37 insertions, 2 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 662991ff91ba..9b2d9bd97458 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -46,6 +46,7 @@
#include <cassert>
#include <cstring>
#include <libxml/parser.h>
+#include <cstdint>
// Inverse of libxml's BAD_CAST.
#define XML_CAST( str ) reinterpret_cast< const char* >( str )
@@ -1364,16 +1365,50 @@ void FastSaxParserImpl::callbackProcessingInstruction( const xmlChar *target, co
xmlEntityPtr FastSaxParserImpl::callbackGetEntity( const xmlChar *name )
{
+ if( !name )
+ return xmlGetPredefinedEntity(name);
+ const char* dname = XML_CAST(name);
for( size_t i = 0; i < mEntityNames.size(); ++i )
{
- if( mEntityNames[i].compareToAscii(XML_CAST(name)) == 0 )
+ if( mEntityNames[i].compareToAscii(dname) == 0 )
{
return xmlNewEntity( nullptr,
- BAD_CAST(OUStringToOString(mEntityNames[i],RTL_TEXTENCODING_UTF8).getStr()),
+ name,
XML_INTERNAL_GENERAL_ENTITY, nullptr, nullptr,
BAD_CAST(OUStringToOString(mEntityReplacements[i],RTL_TEXTENCODING_UTF8).getStr()));
}
}
+ if ( dname[0] == '#' )
+ {
+ sal_uInt32 cval = 0;
+ int_fast16_t lname = strlen(dname);
+ if( lname < 2 )
+ return xmlGetPredefinedEntity(name);
+ if( dname[1] == 'x' || dname[1] == 'X' )
+ {
+ if( lname < 3 )
+ return xmlGetPredefinedEntity(name);
+ cval = static_cast<sal_uInt32>( strtoul( dname + 2, nullptr, 16 ) );
+ if( cval == 0 )
+ return xmlGetPredefinedEntity(name);
+ OUString vname( &cval, 1 );
+ return xmlNewEntity( nullptr,
+ name,
+ XML_INTERNAL_GENERAL_ENTITY, nullptr, nullptr,
+ BAD_CAST(OUStringToOString(vname,RTL_TEXTENCODING_UTF8).getStr()));
+ }
+ else
+ {
+ cval = static_cast<sal_uInt32>( strtoul( dname + 2, nullptr, 10 ) );
+ if( cval == 0 )
+ return xmlGetPredefinedEntity(name);
+ OUString vname( &cval, 1 );
+ return xmlNewEntity( nullptr,
+ name,
+ XML_INTERNAL_GENERAL_ENTITY, nullptr, nullptr,
+ BAD_CAST(OUStringToOString(vname,RTL_TEXTENCODING_UTF8).getStr()));
+ }
+ }
return xmlGetPredefinedEntity(name);
}