Bug #12283
closedFix for Fix for 12006 causes C++ exception
100%
Description
This code fragment from DomElement.C barfs on the call to back() if the jsCode string is empty. This happened to me when I refreshed a WCartesianChart by calling reset() on its model.
void DomElement::callJavaScript(const std::string& jsCode,
bool evenWhenDeleted)
{
++numManipulations_;
// Bug #12006: For safety always append semicolon
std::string terminatedJsCode = jsCode;
if (jsCode.back() != ';') {
terminatedJsCode += ";";
}
if (!evenWhenDeleted)
javaScript_ << terminatedJsCode << '\n';
else
javaScriptEvenWhenDeleted_ += terminatedJsCode;
}
my fix which solves my problem:
void DomElement::callJavaScript(const std::string& jsCode,
bool evenWhenDeleted)
{
++numManipulations_;
// Bug #12006: For safety always append semicolon
if (jsCode.empty())
return;
std::string terminatedJsCode = jsCode;
if (jsCode.back() != ';') {
terminatedJsCode += ";";
}
if (!evenWhenDeleted)
javaScript_ << terminatedJsCode << '\n';
else
javaScriptEvenWhenDeleted_ += terminatedJsCode;
}
Updated by Bruce MacDonald about 1 year ago
... sorry about crappy formatting in my initial report
void DomElement::callJavaScript(const std::string& jsCode,
bool evenWhenDeleted)
{
++numManipulations_;
// Fix for #12283
if (jsCode.empty())
return;
// Bug #12006: For safety always append semicolon
std::string terminatedJsCode = jsCode;
if (jsCode.back() != ';') {
terminatedJsCode += ";";
}
if (!evenWhenDeleted)
javaScript_ << terminatedJsCode << '\n';
else
javaScriptEvenWhenDeleted_ += terminatedJsCode;
}
Updated by Matthias Van Ceulebroeck 12 months ago
- Status changed from New to InProgress
- Assignee set to Matthias Van Ceulebroeck
No worries. Thanks for noticing this oversight.
Updated by Matthias Van Ceulebroeck 12 months ago
- Status changed from InProgress to Review
- Assignee deleted (
Matthias Van Ceulebroeck)
Updated by Bruce MacDonald 12 months ago
Thanks Matthias! FYI, I actually implemented a very slightly different change which doesn't increment numManipulations_
and so far has worked fine for my use cases:
void DomElement::callJavaScript(const std::string& jsCode,
bool evenWhenDeleted)
{
// Bug #12283: Ignore empty jsCode (otherwise jsCode.back() throws)
if (jsCode.empty())
return;
++numManipulations_;
// Bug #12006: For safety always append semicolon
std::string terminatedJsCode = jsCode;
if (jsCode.back() != ';') {
terminatedJsCode += ";";
}
if (!evenWhenDeleted)
javaScript_ << terminatedJsCode << '\n';
else
javaScriptEvenWhenDeleted_ += terminatedJsCode;
}
Updated by Matthias Van Ceulebroeck 3 months ago
- Status changed from Review to Implemented @Emweb
- Assignee changed from Romain Mardulyn to Matthias Van Ceulebroeck
- % Done changed from 0 to 100
Updated by Matthias Van Ceulebroeck 3 months ago
- Status changed from Implemented @Emweb to Closed