diff options
author | vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-09-21 17:50:50 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-09-21 17:50:50 +0000 |
commit | 251a7667d2a3c6b7ebfbf318af9b93744042df06 (patch) | |
tree | 7b3007ba6626835d48e42a6a1998486b280fbfd6 | |
parent | 8136d58161c3fa314af42f5c65682be855dfec1b (diff) |
[PDF] Fix name generation - / needs to be escaped.
BUG=chromium 148422
Review URL: https://codereview.appspot.com/6542044
git-svn-id: http://skia.googlecode.com/svn/trunk@5641 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | src/pdf/SkPDFTypes.cpp | 4 | ||||
-rw-r--r-- | tests/PDFPrimitivesTest.cpp | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp index 210e15e8f9..7fb1e95532 100644 --- a/src/pdf/SkPDFTypes.cpp +++ b/src/pdf/SkPDFTypes.cpp @@ -301,10 +301,12 @@ size_t SkPDFName::getOutputSize(SkPDFCatalog* catalog, bool indirect) { // static SkString SkPDFName::FormatName(const SkString& input) { SkASSERT(input.size() <= kMaxLen); + // TODO(vandebo) If more escaping is needed, improve the linear scan. + static const char escaped[] = "#/%()<>[]{}"; SkString result("/"); for (size_t i = 0; i < input.size(); i++) { - if (input[i] & 0x80 || input[i] < '!' || input[i] == '#') { + if (input[i] & 0x80 || input[i] < '!' || strchr(escaped, input[i])) { result.append("#"); // Mask with 0xFF to avoid sign extension. i.e. #FFFFFF81 result.appendHex(input[i] & 0xFF, 2); diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp index 33366be560..5cbb9057be 100644 --- a/tests/PDFPrimitivesTest.cpp +++ b/tests/PDFPrimitivesTest.cpp @@ -273,6 +273,12 @@ static void TestPDFPrimitives(skiatest::Reporter* reporter) { CheckObjectOutput(reporter, name.get(), expectedResult, strlen(expectedResult), false, false); + SkRefPtr<SkPDFName> escapedName = new SkPDFName("A#/%()<>[]{}B"); + escapedName->unref(); // SkRefPtr and new both took a reference. + const char escapedNameExpected[] = "/A#23#2F#25#28#29#3C#3E#5B#5D#7B#7DB"; + CheckObjectOutput(reporter, escapedName.get(), escapedNameExpected, + strlen(escapedNameExpected), false, false); + // Test that we correctly handle characters with the high-bit set. const unsigned char highBitCString[] = {0xDE, 0xAD, 'b', 'e', 0xEF, 0}; SkRefPtr<SkPDFName> highBitName = new SkPDFName((const char*)highBitCString); |