Auto merge of #25494 - pshaughn:leadingzeroes, r=jdm

Make sure input value=12:30:01 doesn't turn into 12:30:1

Fixed convert_valid_normalized_local_date_and_time_string to add the mandatory leading 0 before seconds values that needed it, added tests to see that various-length strings with zeroes in them would roundtrip properly.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25493

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-02-12 12:37:02 -05:00 committed by GitHub
commit da75ef25a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 0 deletions

View file

@ -474,7 +474,15 @@ impl DOMString {
"{:04}-{:02}-{:02}T{:02}:{:02}",
year, month, day, hour, minute
);
} else if second < 10.0 {
// we need exactly one leading zero on the seconds,
// whatever their total string length might be
self.0 = format!(
"{:04}-{:02}-{:02}T{:02}:{:02}:0{}",
year, month, day, hour, minute, second
);
} else {
// we need no leading zeroes on the seconds
self.0 = format!(
"{:04}-{:02}-{:02}T{:02}:{:02}:{}",
year, month, day, hour, minute, second