1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Allow quoting hypertext attribute values (#14550)

This commit is contained in:
rubenwardy 2024-05-05 13:27:17 +01:00 committed by GitHub
parent d748c8c653
commit 3017b0213b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 20 deletions

View file

@ -421,14 +421,16 @@ u32 ParsedText::parseTag(const wchar_t *text, u32 cursor)
AttrsList attrs;
while (c != L'>') {
std::string attr_name = "";
core::stringw attr_val = L"";
std::wstring attr_val = L"";
// Consume whitespace
while (c == ' ') {
c = text[++cursor];
if (c == L'\0' || c == L'=')
return 0;
}
// Read attribute name
while (c != L' ' && c != L'=') {
attr_name += (char)c;
c = text[++cursor];
@ -436,28 +438,51 @@ u32 ParsedText::parseTag(const wchar_t *text, u32 cursor)
return 0;
}
// Consume whitespace
while (c == L' ') {
c = text[++cursor];
if (c == L'\0' || c == L'>')
return 0;
}
// Skip equals
if (c != L'=')
return 0;
c = text[++cursor];
if (c == L'\0')
return 0;
while (c != L'>' && c != L' ') {
attr_val += c;
// Read optional quote
wchar_t quote_used = 0;
if (c == L'"' || c == L'\'') {
quote_used = c;
c = text[++cursor];
if (c == L'\0')
return 0;
}
attrs[attr_name] = stringw_to_utf8(attr_val);
// Read attribute value
bool escape = false;
while (escape || (quote_used && c != quote_used) || (!quote_used && c != L'>' && c != L' ')) {
if (quote_used && !escape && c == L'\\') {
escape = true;
} else {
escape = false;
attr_val += c;
}
c = text[++cursor];
if (c == L'\0')
return 0;
}
// Remove quote
if (quote_used) {
if (c != quote_used)
return 0;
c = text[++cursor];
}
attrs[attr_name] = wide_to_utf8(attr_val);
}
++cursor; // Last ">"