Skip to content

Commit

Permalink
WT-12006: More robustly place the JS member functions
Browse files Browse the repository at this point in the history
When placing a JS member on a widget, its name and value are remembered.
This is so that if the value is cleared or replaced, we do so for the
same member function.

There, however, exists a special case for member function where if a
single character is assigned to it, it is replaced by an empty value.
This serves to function such that setting the function to `0` for
example, will result in it being empty.

When we appended the semicolon to it, this caused that last piece of
logic to be ignored, and would generate incorrect JS, which called a
function `0;`.
  • Loading branch information
matthias committed Nov 9, 2023
1 parent 1a9892b commit c1abebc
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Wt/WWebWidget.C
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,16 @@ void WWebWidget::setJavaScriptMember(const std::string& name,
std::vector<OtherImpl::Member>& members = *otherImpl_->jsMembers_;
int index = indexOfJavaScriptMember(name);

if (index != -1 && (members[index].value == value))
// Bug #12006: For safety always append semicolon
std::string terminatedValue = value;
// Do not escape the value if it is a "default" placeholder.
// A value of "0" (or any value of length 1) is converted to an empty
// string in setImplementLayoutSizeAware.
if (!terminatedValue.empty() && terminatedValue.back() != ';' && terminatedValue != "0") {
terminatedValue += ";";
}

if (index != -1 && (members[index].value == terminatedValue))
return;

if (value.empty()) {
Expand All @@ -914,14 +923,10 @@ void WWebWidget::setJavaScriptMember(const std::string& name,
if (index == -1) {
OtherImpl::Member m;
m.name = name;
m.value = value;
// Bug #12006: For safety always append semicolon
if (value.back() != ';') {
m.value += ";";
}
m.value = terminatedValue;
members.push_back(m);
} else {
members[index].value = value;
members[index].value = terminatedValue;
}
}

Expand Down

0 comments on commit c1abebc

Please sign in to comment.