Rewrote escape_some_html() slightly and enhanced the test.
All checks were successful
the build was successful
All checks were successful
the build was successful
This commit is contained in:
parent
6ff05f11ff
commit
067fba7447
|
@ -62,6 +62,6 @@ const string get_repo(const string &url);
|
|||
const string get_project(const string &url);
|
||||
|
||||
//! Escape some characters to named HTML entities.
|
||||
const string escape_some_html(const string &html);
|
||||
const string escape_some_html(string html);
|
||||
|
||||
#endif // GITEA2RSS_HPP
|
||||
|
|
|
@ -42,19 +42,19 @@ const string get_project(const string &url)
|
|||
return repo.substr(repo.find('/') + 1);
|
||||
}
|
||||
|
||||
const string escape_some_html(const string &html)
|
||||
const string escape_some_html(string html)
|
||||
{
|
||||
string output = html;
|
||||
const std::map<char, string> names =
|
||||
const std::map<const char, const string> names =
|
||||
{
|
||||
{ '<', "<" },
|
||||
{ '>', ">" }
|
||||
};
|
||||
|
||||
for (auto &pair : names)
|
||||
{
|
||||
const std::regex re(string(1, pair.first));
|
||||
output = std::regex_replace(output, re, pair.second);
|
||||
html = std::regex_replace(html, re, pair.second);
|
||||
}
|
||||
|
||||
return output;
|
||||
return html;
|
||||
}
|
||||
|
|
|
@ -25,11 +25,12 @@ SCENARIO ("escape_some_html() works as expected", "[strings]")
|
|||
WHEN ("String with escape-able characters")
|
||||
{
|
||||
const string escaped
|
||||
= escape_some_html("<Anna & Arthur are escaping HTML.>");
|
||||
= escape_some_html("<p><small>.</small></p>");
|
||||
|
||||
THEN ("The HTML is escaped")
|
||||
{
|
||||
REQUIRE(escaped == "<Anna & Arthur are escaping HTML.>");
|
||||
REQUIRE(escaped ==
|
||||
"<p><small>.</small></p>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user