summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-04-24 17:25:28 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-24 17:25:28 +0000
commit8a95c22dd5d4f7d4e730370c761f41298ba98bf2 (patch)
tree61e7be2078661f891567cbae6b7d625f3822db4b /core
parent273c598ef5e7e9ee210a8e6645b3a83b9f21a1da (diff)
downloadpdfium-8a95c22dd5d4f7d4e730370c761f41298ba98bf2.tar.xz
Cleanup CFX_XMLParser entity conversion
This CL converts the CFX_XMLParser to use the FXSYS methods to convert decimal and hex chars during entity conversion. Change-Id: I7f6c83fc528e95c9f4c2bcdb04f0066da2c15c09 Reviewed-on: https://pdfium-review.googlesource.com/31274 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fxcrt/xml/cfx_xmlparser.cpp17
-rw-r--r--core/fxcrt/xml/cfx_xmlparser_unittest.cpp17
2 files changed, 16 insertions, 18 deletions
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index 09ae64ec8b..21bbbbe9d6 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -661,26 +661,17 @@ void CFX_XMLParser::ParseTextChar(wchar_t character) {
if (iLen > 0) {
if (csEntity[0] == L'#') {
uint32_t ch = 0;
- wchar_t w;
if (iLen > 1 && csEntity[1] == L'x') {
for (int32_t i = 2; i < iLen; i++) {
- w = csEntity[i];
- if (std::iswdigit(w))
- ch = (ch << 4) + w - L'0';
- else if (w >= L'A' && w <= L'F')
- ch = (ch << 4) + w - 55;
- else if (w >= L'a' && w <= L'f')
- ch = (ch << 4) + w - 87;
- else
+ if (!FXSYS_isHexDigit(csEntity[i]))
break;
+ ch = (ch << 4) + FXSYS_HexCharToInt(csEntity[i]);
}
} else {
for (int32_t i = 1; i < iLen; i++) {
- w = csEntity[i];
- if (!std::iswdigit(w))
+ if (!FXSYS_isDecimalDigit(csEntity[i]))
break;
-
- ch = ch * 10 + w - L'0';
+ ch = ch * 10 + FXSYS_DecimalCharToInt(csEntity[i]);
}
}
if (ch > kMaxCharRange)
diff --git a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
index badac2c532..0b51c6b88c 100644
--- a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
@@ -429,11 +429,18 @@ TEST(CFX_XMLParserTest, CommentTwoDash) {
TEST(CFX_XMLParserTest, Entities) {
const char* input =
"<script contentType=\"application/x-javascript\">"
- "&#66;"
- "&#x54;"
- "&#x00000000000000000048;"
- "&#x0000000000000000AB48;"
+ "&#66;" // B
+ "&#x54;" // T
+ "&#x6a;" // j
+ "&#x00000000000000000048;" // H
+ "&#x0000000000000000AB48;" // \xab48
"&#x0000000000000000000;"
+ "&amp;"
+ "&lt;"
+ "&gt;"
+ "&apos;"
+ "&quot;"
+ "&something_else;"
"</script>";
auto stream = MakeProxy(input);
@@ -451,7 +458,7 @@ TEST(CFX_XMLParserTest, Entities) {
ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"BTH\xab48", parser.GetTextData());
+ ASSERT_EQ(L"BTjH\xab48&<>'\"", parser.GetTextData());
ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
ASSERT_EQ(L"script", parser.GetTextData());