Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement value sanitization on HTMLInputElement #18262

Merged
merged 2 commits into from Nov 10, 2017

Conversation

@KiChjang
Copy link
Member

KiChjang commented Aug 27, 2017

@highfive
Copy link

highfive commented Aug 27, 2017

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/htmlinputelement.rs
  • @KiChjang: components/script/dom/htmlinputelement.rs
@KiChjang KiChjang force-pushed the KiChjang:value-sanitization branch 2 times, most recently from a1e26c5 to a81a95c Aug 27, 2017
@KiChjang
Copy link
Member Author

KiChjang commented Sep 29, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Sep 29, 2017

Trying commit a81a95c with merge 6a5654f...

bors-servo added a commit that referenced this pull request Sep 29, 2017
Implement value sanitization on HTMLInputElement

https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18262)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Sep 29, 2017

💔 Test failed - mac-rel-wpt1

@KiChjang KiChjang force-pushed the KiChjang:value-sanitization branch from a81a95c to a188073 Oct 8, 2017
@highfive highfive removed the S-tests-failed label Oct 8, 2017
@KiChjang
Copy link
Member Author

KiChjang commented Oct 8, 2017

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 KiChjang:value-sanitization branch from a188073 to 835c244 Oct 8, 2017
@KiChjang
Copy link
Member Author

KiChjang commented Oct 9, 2017

r? @nox

@highfive highfive assigned nox and unassigned emilio Oct 9, 2017
@@ -176,7 +176,7 @@ impl HTMLInputElement {
.map_or_else(|| atom!(""), |a| a.value().as_atom().to_owned())
}

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

This comment has been minimized.

Copy link
@nox

nox Oct 19, 2017

Member

Why?

This comment has been minimized.

Copy link
@KiChjang

KiChjang Oct 19, 2017

Author Member

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

This comment has been minimized.

Copy link
@nox
@@ -410,8 +410,19 @@ impl HTMLInputElementMethods for HTMLInputElement {
fn SetValue(&self, value: DOMString) -> ErrorResult {
match self.value_mode() {
ValueMode::Value => {
// Step 1.
let old_value = self.textinput.borrow().get_content();

This comment has been minimized.

Copy link
@nox

nox Oct 19, 2017

Member

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

This comment has been minimized.

Copy link
@KiChjang

KiChjang Oct 19, 2017

Author Member

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

This comment has been minimized.

Copy link
@nox

nox Oct 23, 2017

Member

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 {

This comment has been minimized.

Copy link
@nox

nox Oct 19, 2017

Member

This clones the new value for no reason.

This comment has been minimized.

Copy link
@KiChjang

KiChjang Oct 19, 2017

Author Member

Which method call is a clone?

This comment has been minimized.

Copy link
@jdm

jdm Oct 19, 2017

Member

get_content.

This comment has been minimized.

Copy link
@KiChjang

KiChjang Oct 19, 2017

Author Member

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()

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
@nox

nox Oct 19, 2017

Member

This is wrong, that should trim only ASCII whitespace.

This comment has been minimized.

Copy link
@KiChjang

KiChjang Oct 19, 2017

Author Member

Your suggestion doesn't match up with the spec: https://html.spec.whatwg.org/multipage/input.html#url-state-(type=url).

This comment has been minimized.

Copy link
@nox

nox Oct 23, 2017

Member

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()

This comment has been minimized.

Copy link
@nox

nox Oct 19, 2017

Member

This clones the current value for no reason.

This comment has been minimized.

Copy link
@KiChjang

KiChjang Oct 19, 2017

Author Member

Which method call is a clone?

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

This comment has been minimized.

Copy link
@nox

nox Oct 19, 2017

Member

This clones the current value for no reason.

This comment has been minimized.

Copy link
@KiChjang

KiChjang Oct 19, 2017

Author Member

Which method call is a clone?

@KiChjang KiChjang force-pushed the KiChjang:value-sanitization branch from 835c244 to 1cafcc4 Oct 21, 2017
@KiChjang
Copy link
Member Author

KiChjang commented Oct 21, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Oct 21, 2017

Trying commit 1cafcc4 with merge beeea1f...

bors-servo added a commit that referenced this pull request Oct 21, 2017
Implement value sanitization on HTMLInputElement

https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18262)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Oct 21, 2017

💔 Test failed - linux-rel-wpt

@KiChjang KiChjang force-pushed the KiChjang:value-sanitization branch from 1cafcc4 to 2b3e94f Oct 22, 2017
@KiChjang
Copy link
Member Author

KiChjang commented Nov 8, 2017

  ▶ 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
Contributor

bors-servo commented Nov 8, 2017

Testing commit cf1bd6b with merge 8038197...

bors-servo added a commit that referenced this pull request Nov 8, 2017
Implement value sanitization on HTMLInputElement

https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18262)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Nov 9, 2017

💔 Test failed - linux-rel-wpt

@KiChjang KiChjang force-pushed the KiChjang:value-sanitization branch from cf1bd6b to d53a729 Nov 9, 2017
@KiChjang
Copy link
Member Author

KiChjang commented Nov 10, 2017

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
Member Author

KiChjang commented Nov 10, 2017

Filed #19171 for the problem I mentioned above.

@KiChjang KiChjang force-pushed the KiChjang:value-sanitization branch from d53a729 to 8203605 Nov 10, 2017
@KiChjang
Copy link
Member Author

KiChjang commented Nov 10, 2017

@bors-servo r=nox

@bors-servo
Copy link
Contributor

bors-servo commented Nov 10, 2017

📌 Commit 8203605 has been approved by nox

@bors-servo
Copy link
Contributor

bors-servo commented Nov 10, 2017

Testing commit 8203605 with merge 338e2ae...

bors-servo added a commit that referenced this pull request Nov 10, 2017
Implement value sanitization on HTMLInputElement

https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18262)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Nov 10, 2017

@bors-servo bors-servo merged commit 8203605 into servo:master Nov 10, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@bors-servo bors-servo mentioned this pull request Nov 10, 2017
3 of 11 tasks complete
jdm added a commit to web-platform-tests/wpt that referenced this pull request Nov 15, 2017
@tigercosmos tigercosmos mentioned this pull request Nov 26, 2017
3 of 3 tasks complete
@KiChjang KiChjang deleted the KiChjang:value-sanitization branch Mar 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.