Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSubsequent step for implementing HTML form validation #14566
Conversation
highfive
commented
Dec 13, 2016
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. |
highfive
commented
Dec 13, 2016
|
Heads up! This PR modifies the following files: |
highfive
commented
Dec 13, 2016
| Err(err) => { | ||
| match err[0] { | ||
| FormSubmittableElement::InputElement(ref i) => | ||
| println!("First element didn't pass: {}", |
This comment has been minimized.
This comment has been minimized.
Manishearth
Dec 13, 2016
Member
Please don't print to stdout.
@jdm Thought on how this should be reported?
This comment has been minimized.
This comment has been minimized.
jdm
Dec 15, 2016
Member
Stdout is all we've got at the moment. We should be calling Focus() on the element, however.
|
r? @jdm |
|
This is a good start! Please let us know if you intend to continue working on this or if we should find someone else to take over this work, now that the term is over! |
| Err(err) => { | ||
| match err[0] { | ||
| FormSubmittableElement::InputElement(ref i) => | ||
| println!("First element didn't pass: {}", |
This comment has been minimized.
This comment has been minimized.
jdm
Dec 15, 2016
Member
Stdout is all we've got at the moment. We should be calling Focus() on the element, however.
| i.upcast::<Element>().get_string_attribute(&local_name!("name"))), | ||
| FormSubmittableElement::ObjectElement(ref i) => | ||
| println!("First element didn't pass: {}", | ||
| i.upcast::<Element>().get_string_attribute(&local_name!("name"))), |
This comment has been minimized.
This comment has been minimized.
jdm
Dec 15, 2016
Member
As discussed in the evaluation, we should find a way to reduce code duplication here. The reporting belongs in the code beneath here, where it should replace the TODO.
| let window = window_from_node(self); | ||
| let el = self.upcast::<Element>(); | ||
| let vs = ValidityState::new(&window, el); | ||
| if vs.ValueMissing() { |
This comment has been minimized.
This comment has been minimized.
jdm
Dec 15, 2016
Member
I know the comment above says to call methods in validityState, and I apologize for missing that in the previous group's work. However, the model in this PR is backwards - validation code for a particular element type belongs in this validate method, and the methods in ValidityState should be calling this method and passing appropriate ValidationFlags. This method should be checking the state of validate_flags and performing the appropriate validation checks that are requested.
| "email" => Regex::new(r"^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$").unwrap(), | ||
| "url" => Regex::new(r"^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$").unwrap(), | ||
| "date" => Regex::new(r"^\d{1,2}\/\d{1,2}\/\d{4}$").unwrap(), | ||
| "tel" => Regex::new(r"^\d{3}-\d{2}-\d{4}$").unwrap(), |
This comment has been minimized.
This comment has been minimized.
jdm
Dec 15, 2016
Member
Unfortunately these regexes need to be either much more complex, or much less strict. I lean towards much less strict - URLs can check if there's a period present; emails can check if there's an @; telephone numbers should not contain letters.
| if l > Max.parse::<i32>().unwrap() { | ||
| println!("{} is too long for {}, maxlength is {} characters.", v, n, Max); | ||
| return true; | ||
| } |
This comment has been minimized.
This comment has been minimized.
jdm
Dec 15, 2016
Member
HTMLInputElement already contains the maxlength information in a field, so this check will be more straightforward in HTMLInputElement::validate.
|
Hi, Josh,
Thanks for you comments. I will discuss these with my teammate and let you
know what we can do later.
Regards,
Xilai
…On Thu, Dec 15, 2016 at 11:52 AM, Josh Matthews ***@***.***> wrote:
***@***.**** requested changes on this pull request.
This is a good start! Please let us know if you intend to continue working
on this or if we should find someone else to take over this work, now that
the term is over!
------------------------------
In components/script/dom/htmlformelement.rs
<#14566 (review)>:
> @@ -455,7 +455,27 @@ impl HTMLFormElement {
// Step 1-3
let _unhandled_invalid_controls = match self.static_validation() {
Ok(()) => return Ok(()),
- Err(err) => err
+ //Err(err) => err,
+ Err(err) => {
+ match err[0] {
+ FormSubmittableElement::InputElement(ref i) =>
+ println!("First element didn't pass: {}",
Stdout is all we've got at the moment. We should be calling Focus() on
the element, however.
------------------------------
In components/script/dom/htmlformelement.rs
<#14566 (review)>:
> + match err[0] {
+ FormSubmittableElement::InputElement(ref i) =>
+ println!("First element didn't pass: {}",
+ i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
+ FormSubmittableElement::ButtonElement(ref i) =>
+ println!("First element didn't pass: {}",
+ i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
+ FormSubmittableElement::SelectElement(ref i) =>
+ println!("First element didn't pass: {}",
+ i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
+ FormSubmittableElement::TextAreaElement(ref i) =>
+ println!("First elment didn't pass: {}",
+ i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
+ FormSubmittableElement::ObjectElement(ref i) =>
+ println!("First element didn't pass: {}",
+ i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
As discussed in the evaluation, we should find a way to reduce code
duplication here. The reporting belongs in the code beneath here, where it
should replace the TODO.
------------------------------
In components/script/dom/htmlinputelement.rs
<#14566 (review)>:
> @@ -1139,6 +1141,21 @@ impl Validatable for HTMLInputElement {
}
fn validate(&self, _validate_flags: ValidationFlags) -> bool {
// call stub methods defined in validityState.rs file here according to the flags set in validate_flags
+ let window = window_from_node(self);
+ let el = self.upcast::<Element>();
+ let vs = ValidityState::new(&window, el);
+ if vs.ValueMissing() {
I know the comment above says to call methods in validityState, and I
apologize for missing that in the previous group's work. However, the model
in this PR is backwards - validation code for a particular element type
belongs in this validate method, and the methods in ValidityState should
be calling this method and passing appropriate ValidationFlags. This method
should be checking the state of validate_flags and performing the
appropriate validation checks that are requested.
------------------------------
In components/script/dom/validitystate.rs
<#14566 (review)>:
> false
}
// https://html.spec.whatwg.org/multipage/#dom-validitystate-typemismatch
fn TypeMismatch(&self) -> bool {
+ if self.element.has_attribute(&local_name!("type")) {
+ let content_type = self.element.get_string_attribute(&local_name!("type"));
+ let content_value = self.element.get_string_attribute(&local_name!("value"));
+ let re = match content_type.to_string().as_ref() {
+ "email" => ***@***.***A-Z_]+?\.[a-zA-Z]{2,3}$").unwrap(),
+ "url" => Regex::new(r"^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$").unwrap(),
+ "date" => Regex::new(r"^\d{1,2}\/\d{1,2}\/\d{4}$").unwrap(),
+ "tel" => Regex::new(r"^\d{3}-\d{2}-\d{4}$").unwrap(),
Unfortunately these regexes need to be either much more complex, or much
less strict. I lean towards much less strict - URLs can check if there's a
period present; emails can check if there's an @; telephone numbers should
not contain letters.
------------------------------
In components/script/dom/validitystate.rs
<#14566 (review)>:
> @@ -84,11 +111,33 @@ impl ValidityStateMethods for ValidityState {
// https://html.spec.whatwg.org/multipage/#dom-validitystate-toolong
fn TooLong(&self) -> bool {
+ if self.element.has_attribute(&local_name!("maxlength")) {
+ let Max = self.element.get_string_attribute(&local_name!("maxlength")).to_string();
+ let v = self.element.get_string_attribute(&local_name!("value")).to_string();
+ let n = self.element.get_string_attribute(&local_name!("name"));
+ let l = v.len().to_i32().unwrap();
+ if l > Max.parse::<i32>().unwrap() {
+ println!("{} is too long for {}, maxlength is {} characters.", v, n, Max);
+ return true;
+ }
HTMLInputElement already contains the maxlength information in a field, so
this check will be more straightforward in HTMLInputElement::validate.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#14566 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ANV-klrMwZp8RLXVMpGbCsMuJffx4k33ks5rIXBagaJpZM4LLefK>
.
--
Xilai Li
Research Assistant
Department of Electrical and Computer Engineering
North Carolina State University
Raleigh, NC, USA
Email: xli47@ncsu.edu
Tel(mobile): 919- <919-389-1113>666-7899
|
|
Hi, Josh,
We intend to continue working on this project. We will improve our
modification according to your comments.
Xilai
…On Thu, Dec 15, 2016 at 11:52 AM, Josh Matthews ***@***.***> wrote:
***@***.**** requested changes on this pull request.
This is a good start! Please let us know if you intend to continue working
on this or if we should find someone else to take over this work, now that
the term is over!
------------------------------
In components/script/dom/htmlformelement.rs
<#14566 (review)>:
> @@ -455,7 +455,27 @@ impl HTMLFormElement {
// Step 1-3
let _unhandled_invalid_controls = match self.static_validation() {
Ok(()) => return Ok(()),
- Err(err) => err
+ //Err(err) => err,
+ Err(err) => {
+ match err[0] {
+ FormSubmittableElement::InputElement(ref i) =>
+ println!("First element didn't pass: {}",
Stdout is all we've got at the moment. We should be calling Focus() on
the element, however.
------------------------------
In components/script/dom/htmlformelement.rs
<#14566 (review)>:
> + match err[0] {
+ FormSubmittableElement::InputElement(ref i) =>
+ println!("First element didn't pass: {}",
+ i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
+ FormSubmittableElement::ButtonElement(ref i) =>
+ println!("First element didn't pass: {}",
+ i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
+ FormSubmittableElement::SelectElement(ref i) =>
+ println!("First element didn't pass: {}",
+ i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
+ FormSubmittableElement::TextAreaElement(ref i) =>
+ println!("First elment didn't pass: {}",
+ i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
+ FormSubmittableElement::ObjectElement(ref i) =>
+ println!("First element didn't pass: {}",
+ i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
As discussed in the evaluation, we should find a way to reduce code
duplication here. The reporting belongs in the code beneath here, where it
should replace the TODO.
------------------------------
In components/script/dom/htmlinputelement.rs
<#14566 (review)>:
> @@ -1139,6 +1141,21 @@ impl Validatable for HTMLInputElement {
}
fn validate(&self, _validate_flags: ValidationFlags) -> bool {
// call stub methods defined in validityState.rs file here according to the flags set in validate_flags
+ let window = window_from_node(self);
+ let el = self.upcast::<Element>();
+ let vs = ValidityState::new(&window, el);
+ if vs.ValueMissing() {
I know the comment above says to call methods in validityState, and I
apologize for missing that in the previous group's work. However, the model
in this PR is backwards - validation code for a particular element type
belongs in this validate method, and the methods in ValidityState should
be calling this method and passing appropriate ValidationFlags. This method
should be checking the state of validate_flags and performing the
appropriate validation checks that are requested.
------------------------------
In components/script/dom/validitystate.rs
<#14566 (review)>:
> false
}
// https://html.spec.whatwg.org/multipage/#dom-validitystate-typemismatch
fn TypeMismatch(&self) -> bool {
+ if self.element.has_attribute(&local_name!("type")) {
+ let content_type = self.element.get_string_attribute(&local_name!("type"));
+ let content_value = self.element.get_string_attribute(&local_name!("value"));
+ let re = match content_type.to_string().as_ref() {
+ "email" => ***@***.***A-Z_]+?\.[a-zA-Z]{2,3}$").unwrap(),
+ "url" => Regex::new(r"^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$").unwrap(),
+ "date" => Regex::new(r"^\d{1,2}\/\d{1,2}\/\d{4}$").unwrap(),
+ "tel" => Regex::new(r"^\d{3}-\d{2}-\d{4}$").unwrap(),
Unfortunately these regexes need to be either much more complex, or much
less strict. I lean towards much less strict - URLs can check if there's a
period present; emails can check if there's an @; telephone numbers should
not contain letters.
------------------------------
In components/script/dom/validitystate.rs
<#14566 (review)>:
> @@ -84,11 +111,33 @@ impl ValidityStateMethods for ValidityState {
// https://html.spec.whatwg.org/multipage/#dom-validitystate-toolong
fn TooLong(&self) -> bool {
+ if self.element.has_attribute(&local_name!("maxlength")) {
+ let Max = self.element.get_string_attribute(&local_name!("maxlength")).to_string();
+ let v = self.element.get_string_attribute(&local_name!("value")).to_string();
+ let n = self.element.get_string_attribute(&local_name!("name"));
+ let l = v.len().to_i32().unwrap();
+ if l > Max.parse::<i32>().unwrap() {
+ println!("{} is too long for {}, maxlength is {} characters.", v, n, Max);
+ return true;
+ }
HTMLInputElement already contains the maxlength information in a field, so
this check will be more straightforward in HTMLInputElement::validate.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#14566 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ANV-klrMwZp8RLXVMpGbCsMuJffx4k33ks5rIXBagaJpZM4LLefK>
.
--
Xilai Li
Research Assistant
Department of Electrical and Computer Engineering
North Carolina State University
Raleigh, NC, USA
Email: xli47@ncsu.edu
Tel(mobile): 919- <919-389-1113>666-7899
|
|
Wonderful! I look forward to seeing the changes! |
|
Currently many of us are having vacation, we might probably resume after
the break.
Thank you,
Zhongcan
P.S. I'm not able to access the comments on the pull request, so Josh could
you add me to that, if convenient. If it's not very convenient its OK, we
just will continue using Xilai's account. My id is: canhsiao.
…On Mon, Dec 19, 2016 at 2:15 PM, Xilai Li ***@***.***> wrote:
Hi, Josh,
We intend to continue working on this project. We will improve our
modification according to your comments.
Xilai
On Thu, Dec 15, 2016 at 11:52 AM, Josh Matthews ***@***.***>
wrote:
> ***@***.**** requested changes on this pull request.
>
> This is a good start! Please let us know if you intend to continue
> working on this or if we should find someone else to take over this work,
> now that the term is over!
> ------------------------------
>
> In components/script/dom/htmlformelement.rs
> <#14566 (review)>:
>
> > @@ -455,7 +455,27 @@ impl HTMLFormElement {
> // Step 1-3
> let _unhandled_invalid_controls = match self.static_validation() {
> Ok(()) => return Ok(()),
> - Err(err) => err
> + //Err(err) => err,
> + Err(err) => {
> + match err[0] {
> + FormSubmittableElement::InputElement(ref i) =>
> + println!("First element didn't pass: {}",
>
> Stdout is all we've got at the moment. We should be calling Focus() on
> the element, however.
> ------------------------------
>
> In components/script/dom/htmlformelement.rs
> <#14566 (review)>:
>
> > + match err[0] {
> + FormSubmittableElement::InputElement(ref i) =>
> + println!("First element didn't pass: {}",
> + i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
> + FormSubmittableElement::ButtonElement(ref i) =>
> + println!("First element didn't pass: {}",
> + i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
> + FormSubmittableElement::SelectElement(ref i) =>
> + println!("First element didn't pass: {}",
> + i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
> + FormSubmittableElement::TextAreaElement(ref i) =>
> + println!("First elment didn't pass: {}",
> + i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
> + FormSubmittableElement::ObjectElement(ref i) =>
> + println!("First element didn't pass: {}",
> + i.upcast::<Element>().get_string_attribute(&local_name!("name"))),
>
> As discussed in the evaluation, we should find a way to reduce code
> duplication here. The reporting belongs in the code beneath here, where it
> should replace the TODO.
> ------------------------------
>
> In components/script/dom/htmlinputelement.rs
> <#14566 (review)>:
>
> > @@ -1139,6 +1141,21 @@ impl Validatable for HTMLInputElement {
> }
> fn validate(&self, _validate_flags: ValidationFlags) -> bool {
> // call stub methods defined in validityState.rs file here according to the flags set in validate_flags
> + let window = window_from_node(self);
> + let el = self.upcast::<Element>();
> + let vs = ValidityState::new(&window, el);
> + if vs.ValueMissing() {
>
> I know the comment above says to call methods in validityState, and I
> apologize for missing that in the previous group's work. However, the model
> in this PR is backwards - validation code for a particular element type
> belongs in this validate method, and the methods in ValidityState should
> be calling this method and passing appropriate ValidationFlags. This method
> should be checking the state of validate_flags and performing the
> appropriate validation checks that are requested.
> ------------------------------
>
> In components/script/dom/validitystate.rs
> <#14566 (review)>:
>
> > false
> }
>
> // https://html.spec.whatwg.org/multipage/#dom-validitystate-typemismatch
> fn TypeMismatch(&self) -> bool {
> + if self.element.has_attribute(&local_name!("type")) {
> + let content_type = self.element.get_string_attribute(&local_name!("type"));
> + let content_value = self.element.get_string_attribute(&local_name!("value"));
> + let re = match content_type.to_string().as_ref() {
> + "email" => ***@***.***A-Z_]+?\.[a-zA-Z]{2,3}$").unwrap(),
> + "url" => Regex::new(r"^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$").unwrap(),
> + "date" => Regex::new(r"^\d{1,2}\/\d{1,2}\/\d{4}$").unwrap(),
> + "tel" => Regex::new(r"^\d{3}-\d{2}-\d{4}$").unwrap(),
>
> Unfortunately these regexes need to be either much more complex, or much
> less strict. I lean towards much less strict - URLs can check if there's a
> period present; emails can check if there's an @; telephone numbers should
> not contain letters.
> ------------------------------
>
> In components/script/dom/validitystate.rs
> <#14566 (review)>:
>
> > @@ -84,11 +111,33 @@ impl ValidityStateMethods for ValidityState {
>
> // https://html.spec.whatwg.org/multipage/#dom-validitystate-toolong
> fn TooLong(&self) -> bool {
> + if self.element.has_attribute(&local_name!("maxlength")) {
> + let Max = self.element.get_string_attribute(&local_name!("maxlength")).to_string();
> + let v = self.element.get_string_attribute(&local_name!("value")).to_string();
> + let n = self.element.get_string_attribute(&local_name!("name"));
> + let l = v.len().to_i32().unwrap();
> + if l > Max.parse::<i32>().unwrap() {
> + println!("{} is too long for {}, maxlength is {} characters.", v, n, Max);
> + return true;
> + }
>
> HTMLInputElement already contains the maxlength information in a field,
> so this check will be more straightforward in HTMLInputElement::validate.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#14566 (review)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ANV-klrMwZp8RLXVMpGbCsMuJffx4k33ks5rIXBagaJpZM4LLefK>
> .
>
--
Xilai Li
Research Assistant
Department of Electrical and Computer Engineering
North Carolina State University
Raleigh, NC, USA
Email: ***@***.***
Tel(mobile): 919- <919-389-1113>666-7899
|
|
That's fine! I'm not sure what you mean about accessing the comments, though. They should appear in the github UI for anybody to view them and/or respond. |
|
I suppose they're using the email interface instead of the GitHub UI? If so, the URL link to the pull request is #14566. It's possible that they do not have a GitHub account, barring them from commenting on this PR using the GitHub UI. |
|
|
|
@xilaili Are you still planning to finish this work? |
|
Sorry, Josh, We probably cannot continue the work.
Xilai
On Fri, Jan 27, 2017 at 2:11 PM Josh Matthews ***@***.***> wrote:
@xilaili <https://github.com/xilaili> Are you still planning to finish
this work?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14566 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ANV-kjy-zbcAj8WlQbofdkLtBQrXY72cks5rWkE8gaJpZM4LLefK>
.
--
null
|
|
Ok! We'll keep tracking the efforts to finish this work in #11444. |
xilaili commentedDec 13, 2016
•
edited by larsbergstrom
Form validation project. NCSU M1653 student project.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is