aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2023-12-21 23:14:28 +0100
committerJay Berkenbilt <ejb@ql.org>2023-12-21 23:43:29 +0100
commit4400ce84eeb204cdcb35950dd8fde094fc249051 (patch)
tree2a60ae462f22d21b35214a3fdaa4af5d63f8b149 /libqpdf
parentbb12a7ff8df1582a2cb0583bc463a84f5a736219 (diff)
downloadqpdf-4400ce84eeb204cdcb35950dd8fde094fc249051.tar.zst
Add "n:/pdf-name" to qpdf JSON for binary names (fixes #1072)
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDF_Name.cc10
-rw-r--r--libqpdf/QPDF_json.cc8
2 files changed, 17 insertions, 1 deletions
diff --git a/libqpdf/QPDF_Name.cc b/libqpdf/QPDF_Name.cc
index 4597372e..5fde9c65 100644
--- a/libqpdf/QPDF_Name.cc
+++ b/libqpdf/QPDF_Name.cc
@@ -57,6 +57,14 @@ QPDF_Name::getJSON(int json_version)
if (json_version == 1) {
return JSON::makeString(normalizeName(this->name));
} else {
- return JSON::makeString(this->name);
+ bool has_8bit_chars;
+ bool is_valid_utf8;
+ bool is_utf16;
+ QUtil::analyze_encoding(this->name, has_8bit_chars, is_valid_utf8, is_utf16);
+ if (!has_8bit_chars || is_valid_utf8) {
+ return JSON::makeString(this->name);
+ } else {
+ return JSON::makeString("n:" + normalizeName(this->name));
+ }
}
}
diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc
index f8fd689a..864e1a56 100644
--- a/libqpdf/QPDF_json.cc
+++ b/libqpdf/QPDF_json.cc
@@ -144,6 +144,12 @@ is_name(std::string const& v)
return ((v.length() > 1) && (v.at(0) == '/'));
}
+static bool
+is_pdf_name(std::string const& v)
+{
+ return ((v.length() > 3) && (v.substr(0, 3) == "n:/"));
+}
+
bool
QPDF::test_json_validators()
{
@@ -740,6 +746,8 @@ QPDF::JSONReactor::makeObject(JSON const& value)
result = QPDFObjectHandle::newString(QUtil::hex_decode(str));
} else if (is_name(str_v)) {
result = QPDFObjectHandle::newName(str_v);
+ } else if (is_pdf_name(str_v)) {
+ result = QPDFObjectHandle::parse(str_v.substr(2));
} else {
QTC::TC("qpdf", "QPDF_json unrecognized string value");
error(value.getStart(), "unrecognized string value");