Skip to content

Implement value sanitization on HTMLInputElement - #18262

Merged
bors-servo merged 2 commits into
servo:masterfrom
KiChjang:value-sanitization
Nov 10, 2017
Merged

bors-servo merged 2 commits into
servo:masterfrom
KiChjang:value-sanitization

Conversation

@KiChjang

@KiChjang KiChjang commented Aug 27, 2017 •

Copy link
Copy Markdown
Contributor

@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/htmlinputelement.rs
  • @KiChjang: components/script/dom/htmlinputelement.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Aug 27, 2017
@KiChjang
KiChjang force-pushed the value-sanitization branch 2 times, most recently from a1e26c5 to a81a95c Compare August 29, 2017 11:40
@KiChjang

Copy link
Copy Markdown
Contributor Author

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit a81a95c with merge 6a5654f...

@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-wpt1

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Sep 29, 2017
@KiChjang
KiChjang force-pushed the value-sanitization branch from a81a95c to a188073 Compare October 8, 2017 03:53
@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Oct 8, 2017
@KiChjang

KiChjang commented Oct 8, 2017

Copy link
Copy Markdown
Contributor Author

Ok, so the timeouts are actually moving us in the correct direction, the problem is simply that we have a buggy selection algorithm, causing select events to not fire when they're supposed to.

@KiChjang
KiChjang force-pushed the value-sanitization branch from a188073 to 835c244 Compare October 8, 2017 18:59
@KiChjang

KiChjang commented Oct 9, 2017

Copy link
Copy Markdown
Contributor Author

r? @nox

@highfive highfive assigned nox and unassigned emilio Oct 9, 2017
}

// https://html.spec.whatwg.org/multipage/#input-type-attr-summary
// https://html.spec.whatwg.org/multipage/#common-input-element-apis

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the old link doesn't point to somewhere that can explain value modes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match self.value_mode() {
ValueMode::Value => {
// Step 1.
let old_value = self.textinput.borrow().get_content();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge these 2 steps together so that the older value doesn't get cloned.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to clone the old value so that we may compare it in step 5.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No you don't, merge these two steps and use mem::replace and you don't need the clone.

// Step 4.
self.sanitize_value();
// Step 5.
if self.textinput.borrow().get_content() != old_value {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clones the new value for no reason.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which method call is a clone?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_content.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I'm not sure which other method gets the content of the text input without using get_content.

fn sanitize_value(&self) {
let new_value = match self.type_() {
atom!("text") | atom!("search") | atom!("tel") | atom!("password") => {
DOMString::from(self.textinput.borrow().get_content()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.collect::<String>())
}
atom!("url") => {
DOMString::from(self.textinput.borrow().get_content()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.chars()
.filter(|&c| c != '\r' && c != '\n')
.collect::<String>()
.trim_matches(char::is_whitespace))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, that should trim only ASCII whitespace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What?

The value sanitization algorithm is as follows: Strip newlines from the value, then strip leading and trailing ASCII whitespace from the value.

fn sanitize_value(&self) {
let new_value = match self.type_() {
atom!("text") | atom!("search") | atom!("tel") | atom!("password") => {
DOMString::from(self.textinput.borrow().get_content()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clones the current value for no reason.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which method call is a clone?

.collect::<String>())
}
atom!("url") => {
DOMString::from(self.textinput.borrow().get_content()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clones the current value for no reason.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which method call is a clone?

@nox nox added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Oct 19, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Oct 21, 2017
@KiChjang

Copy link
Copy Markdown
Contributor Author

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 1cafcc4 with merge beeea1f...

@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Oct 21, 2017
@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Oct 22, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit cf1bd6b has been approved by nox

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 8, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit cf1bd6b with merge 38bad81...

@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Nov 8, 2017
@KiChjang

KiChjang commented Nov 8, 2017

Copy link
Copy Markdown
Contributor Author
  ▶ TIMEOUT [expected OK] /html/semantics/forms/textfieldselection/selection-start-end.html
  │ 
  │ VMware, Inc.
  │ softpipe
  └ 3.3 (Core Profile) Mesa 17.3.0-devel

So the test harness does actually timeout on this test... will investigate.

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit cf1bd6b with merge 8038197...

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Nov 8, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Nov 9, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Nov 9, 2017
@KiChjang

Copy link
Copy Markdown
Contributor Author

Ok, so it looks like the test SHOULD time out with these changes, because our setSelectionStart and setSelectionEnd implementation isn't exactly up to spec, since they both don't fire a select event at the input element when they're supposed to.

@KiChjang

Copy link
Copy Markdown
Contributor Author

Filed #19171 for the problem I mentioned above.

@KiChjang

Copy link
Copy Markdown
Contributor Author

@bors-servo r=nox

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 8203605 has been approved by nox

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 8203605 with merge 338e2ae...

@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: nox
Pushing 338e2ae to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants