Skip to content

Commit c491927

Browse files
committed
Extra unit test
Have a test with attributes where text was removed from the main body, and the attributes are still in the xML tree. #977
1 parent 2ac6e95 commit c491927

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

editor/html2usfm.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,11 @@ void Editor_Html2Usfm::close_element_node (const pugi::xml_node& node)
288288
if (!wla_class.empty()) {
289289
const std::string contents = m_word_level_attributes[wla_class];
290290
m_word_level_attributes.erase(wla_class);
291-
// The vertical bar separates the canonical word from the attribute(s) following it.
292-
current_line.append("|");
293-
current_line.append(contents);
291+
if (!contents.empty()) {
292+
// The vertical bar separates the canonical word from the attribute(s) following it.
293+
current_line.append("|");
294+
current_line.append(contents);
295+
}
294296
}
295297
// Add closing USFM, optionally closing embedded tags in reverse order.
296298
character_styles = filter::strings::array_diff (character_styles, classes);

unittests/usfm-html.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,4 +1783,18 @@ TEST_F (usfm_html, word_level_attributes_linking)
17831783
}
17841784

17851785

1786+
TEST_F (usfm_html, word_level_attributes_removed)
1787+
{
1788+
// This tests a situation where the \w ... is removed from the text body,
1789+
// but the word-level attributes themselves are still in the XML tree.
1790+
const std::string html = R"(<p class="b-p"><span>A</span><span class="i-w0wla2">B</span></p><p class="b-wordlevelattributes"> </p><p class="b-wla1">C="D"</p>)";
1791+
const std::string usfm = R"(\p A\w B\w*)";
1792+
Editor_Html2Usfm editor_html2usfm;
1793+
editor_html2usfm.load (html);
1794+
editor_html2usfm.stylesheet (styles_logic_standard_sheet ());
1795+
editor_html2usfm.run ();
1796+
EXPECT_EQ (usfm, editor_html2usfm.get());
1797+
}
1798+
1799+
17861800
#endif

0 commit comments

Comments
 (0)