Project

General

Profile

Actions

Bug #11307

closed

Several validators don't copy WString before applying args

Added by Roel Standaert almost 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Roel Standaert
Category:
-
Target version:
Start date:
02/03/2023
Due date:
% Done:

100%

Estimated time:

Description

Many validators allow changing the error message, e.g. WIntValidator has a setInvalidTooSmallText(...).

If this setter is used, then calls to invalidTooSmallText() will not create a copy of that string, but they will bind arguments to it:

WIntValidator intValidator = new WIntValidator();
intValidator.setBottom(1);
WString text = new WString("number must be between {1} and {2}");
intValidator.setInvalidTooSmallText(text);
WString tooSmall = intValidator.getInvalidTooSmallText();
assert text != tooSmall; // ASSERTION ERROR

Further calls to getInvalidTooSmallText() will bind more parameters:

WString tooSmall2 = intValidator.getInvalidTooSmallText();
assert tooSmall2.getArgs().size() == 2; // ASSERTION ERROR, getArgs().size() is 4!

The reason for this is that while Wt makes a copy of the original WString, like:

WString s = tooSmallText_; // Copy constructed used here
s.arg(bottom_).arg(top_);
return s;

However, in JWt this is translated to:

WString s = this.tooSmallText_; // Reference assignment, s and tooSmallText_ point to the same object!
s.arg(this.bottom_).arg(this.top_);
return s;

I propose that we either add a copy constructor to WString in JWt, or implement the clone() function, and make sure we use it.

I have verified that the following validators are affected:

  • WIntValidator
  • WDoubleValidator
  • WDateValidator
  • WTimeValidator
  • WLengthValidator
Actions #1

Updated by Roel Standaert almost 2 years ago

  • Status changed from InProgress to Review
  • Assignee deleted (Roel Standaert)
  • Target version set to 4.9.2
Actions #2

Updated by Roel Standaert almost 2 years ago

  • Assignee set to Matthias Van Ceulebroeck
Actions #3

Updated by Roel Standaert over 1 year ago

  • Status changed from Review to Implemented @Emweb
  • Assignee changed from Matthias Van Ceulebroeck to Roel Standaert
  • % Done changed from 0 to 100
Actions #4

Updated by Roel Standaert over 1 year ago

  • Status changed from Implemented @Emweb to Resolved
Actions #5

Updated by Roel Standaert over 1 year ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF