diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-04-06 22:32:14 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-04-19 12:59:37 +0200 |
| commit | 7a47f00a7ff3f95ef4013bf453340b94c8535e07 (patch) | |
| tree | 134b34a64892e470c66cc599435f28e6b8190a23 | |
| parent | c6387f885fd39e901189b6c73fca0a28cc9ec85b (diff) | |
Remove xmlns:xs namespace from subtitle XML (DoM #2498).
| -rw-r--r-- | src/smpte_subtitle_asset.cc | 2 | ||||
| -rw-r--r-- | src/subtitle_asset.cc | 14 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 2 | ||||
| -rw-r--r-- | test/data/2007.mxf | bin | 17287 -> 17243 bytes | |||
| -rw-r--r-- | test/data/2010.mxf | bin | 17287 -> 17243 bytes | |||
| -rw-r--r-- | test/data/2014.mxf | bin | 17287 -> 17243 bytes | |||
| -rw-r--r-- | test/shared_subtitle_test.cc | 8 | ||||
| -rw-r--r-- | test/smpte_subtitle_test.cc | 2 | ||||
| -rw-r--r-- | test/verify_test.cc | 4 |
9 files changed, 17 insertions, 15 deletions
diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 6db90b2e..3a58ba8e 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -381,7 +381,7 @@ SMPTESubtitleAsset::xml_as_string () const subtitles_as_xml (root->add_child("SubtitleList"), _time_code_rate, Standard::SMPTE); - return format_xml(doc, { {"", schema_namespace()}, {"xs", "http://www.w3.org/2001/XMLSchema"} }); + return format_xml(doc, std::make_pair(string{}, schema_namespace())); } diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 4baa7b06..d6103a1d 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -893,23 +893,23 @@ format_xml_node (xmlpp::Node const* node, State& state) * to <Text> nodes. This is an attempt to avoid changing what is actually displayed as subtitles * while also formatting the XML in such a way as to avoid DoM bug 2205. * - * namespace is a list of namespaces for the root node; it would be nicer to set these up with - * set_namespace_declaration in the caller and then to extract them here but I couldn't find a way + * xml_namespace is an optional namespace for the root node; it would be nicer to set this up with + * set_namespace_declaration in the caller and then to extract it here but I couldn't find a way * to get all namespaces with the libxml++ API. */ string -SubtitleAsset::format_xml (xmlpp::Document const& document, vector<pair<string, string>> const& namespaces) +SubtitleAsset::format_xml(xmlpp::Document const& document, optional<pair<string, string>> xml_namespace) { auto root = document.get_root_node(); State state = {}; state.xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<" + root->get_name(); - for (auto const& ns: namespaces) { - if (ns.first.empty()) { - state.xml += String::compose(" xmlns=\"%1\"", ns.second); + if (xml_namespace) { + if (xml_namespace->first.empty()) { + state.xml += String::compose(" xmlns=\"%1\"", xml_namespace->second); } else { - state.xml += String::compose(" xmlns:%1=\"%2\"", ns.first, ns.second); + state.xml += String::compose(" xmlns:%1=\"%2\"", xml_namespace->first, xml_namespace->second); } } diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 012050b1..28db9574 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -135,7 +135,7 @@ public: virtual SubtitleStandard subtitle_standard() const = 0; - static std::string format_xml (xmlpp::Document const& document, std::vector<std::pair<std::string, std::string>> const& namespaces); + static std::string format_xml(xmlpp::Document const& document, boost::optional<std::pair<std::string, std::string>> xml_namespace); protected: friend struct ::interop_dcp_font_test; diff --git a/test/data/2007.mxf b/test/data/2007.mxf Binary files differindex be085a9c..fafe7768 100644 --- a/test/data/2007.mxf +++ b/test/data/2007.mxf diff --git a/test/data/2010.mxf b/test/data/2010.mxf Binary files differindex 60f20108..29ba626d 100644 --- a/test/data/2010.mxf +++ b/test/data/2010.mxf diff --git a/test/data/2014.mxf b/test/data/2014.mxf Binary files differindex a757dc31..43d0cded 100644 --- a/test/data/2014.mxf +++ b/test/data/2014.mxf diff --git a/test/shared_subtitle_test.cc b/test/shared_subtitle_test.cc index 9c841f90..69ae2be4 100644 --- a/test/shared_subtitle_test.cc +++ b/test/shared_subtitle_test.cc @@ -51,10 +51,10 @@ #include <boost/test/unit_test.hpp> -using std::string; +using std::make_shared; using std::shared_ptr; +using std::string; using std::vector; -using std::make_shared; using boost::optional; @@ -183,9 +183,9 @@ BOOST_AUTO_TEST_CASE (format_xml_test1) fred->add_child_text("Fred"); fred->add_child("Text")->add_child_text("Jim"); fred->add_child_text("Sheila"); - BOOST_REQUIRE_EQUAL (dcp::SubtitleAsset::format_xml(doc, { {"", "fred"}, {"jim", "sheila"} }), + BOOST_REQUIRE_EQUAL (dcp::SubtitleAsset::format_xml(doc, make_pair(string{}, string{"fred"})), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" -"<Foo xmlns=\"fred\" xmlns:jim=\"sheila\">\n" +"<Foo xmlns=\"fred\">\n" " <Empty/>\n" " <Text>Hello world</Text>\n" " <Font>\n" diff --git a/test/smpte_subtitle_test.cc b/test/smpte_subtitle_test.cc index b271b02c..f66ca055 100644 --- a/test/smpte_subtitle_test.cc +++ b/test/smpte_subtitle_test.cc @@ -722,6 +722,8 @@ BOOST_AUTO_TEST_CASE(smpte_subtitle_standard_written_correctly) dcp::SMPTESubtitleAsset test_2014; test_2014.set_issue_date(dcp::LocalTime("2020-01-01T14:00:00")); test_2014.write(out / "2014.mxf"); + std::cout << dcp::SMPTESubtitleAsset(ref / "2014.mxf").raw_xml() << "\n"; + std::cout << dcp::SMPTESubtitleAsset(out / "2014.mxf").raw_xml() << "\n"; BOOST_CHECK(dcp::SMPTESubtitleAsset(ref / "2014.mxf").raw_xml() == dcp::SMPTESubtitleAsset(out / "2014.mxf").raw_xml()); dcp::SMPTESubtitleAsset test_2010(dcp::SubtitleStandard::SMPTE_2010); diff --git a/test/verify_test.cc b/test/verify_test.cc index e182f05d..1484dfb1 100644 --- a/test/verify_test.cc +++ b/test/verify_test.cc @@ -1421,7 +1421,7 @@ BOOST_AUTO_TEST_CASE (verify_invalid_closed_caption_xml_size_in_bytes) { dcp::VerificationNote::Type::BV21_ERROR, dcp::VerificationNote::Code::INVALID_CLOSED_CAPTION_XML_SIZE_IN_BYTES, - string("419336"), + string("419292"), canonical(dir / "subs.mxf") }, { dcp::VerificationNote::Type::WARNING, dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME }, @@ -1461,7 +1461,7 @@ verify_timed_text_asset_too_large (string name) check_verify_result ( { dir }, { - { dcp::VerificationNote::Type::BV21_ERROR, dcp::VerificationNote::Code::INVALID_TIMED_TEXT_SIZE_IN_BYTES, string("121695532"), canonical(dir / "subs.mxf") }, + { dcp::VerificationNote::Type::BV21_ERROR, dcp::VerificationNote::Code::INVALID_TIMED_TEXT_SIZE_IN_BYTES, string("121695488"), canonical(dir / "subs.mxf") }, { dcp::VerificationNote::Type::BV21_ERROR, dcp::VerificationNote::Code::INVALID_TIMED_TEXT_FONT_SIZE_IN_BYTES, string("121634816"), canonical(dir / "subs.mxf") }, { dcp::VerificationNote::Type::BV21_ERROR, dcp::VerificationNote::Code::MISSING_SUBTITLE_START_TIME, canonical(dir / "subs.mxf") }, { dcp::VerificationNote::Type::WARNING, dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME }, |
