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

Polyfill: Throw RangeError if there's an invalid offset string in ZonedDateTime-representing property bags #1976

Merged
merged 1 commit into from
Dec 15, 2021

Conversation

justingrant
Copy link
Collaborator

Ensure that the correct RangeError is thrown when an invalid offset is passed to ParseTimeZoneOffsetString.

Note that validation of the offset in ISO strings is handled separately; this PR only fixes cases where an offset is parsed on its own, e.g. when property bag inputs are used in ZonedDateTime#(with|from|equals|until|since|compare) or as relativeTo options passed to Duration#(add|subtract|compare|round|total). The problem was also present in TimeZone.from and ZonedDateTime#withTimeZone but was caught downstream so didn't fail any previous tests.

Fixes #1972.

@codecov
Copy link

codecov bot commented Dec 13, 2021

Codecov Report

Merging #1976 (c83a394) into main (90ee179) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1976   +/-   ##
=======================================
  Coverage   94.96%   94.96%           
=======================================
  Files          19       19           
  Lines       10953    10962    +9     
  Branches     1740     1742    +2     
=======================================
+ Hits        10401    10410    +9     
  Misses        535      535           
  Partials       17       17           
Flag Coverage Δ
test262 79.99% <83.33%> (-0.05%) ⬇️
tests 89.86% <95.83%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
polyfill/lib/ecmascript.mjs 95.25% <100.00%> (+<0.01%) ⬆️
polyfill/lib/timezone.mjs 93.50% <100.00%> (+0.04%) ⬆️
polyfill/lib/zoneddatetime.mjs 98.50% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 90ee179...c83a394. Read the comment docs.

@justingrant justingrant added no-spec-text PR can be ignored by implementors non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE! labels Dec 13, 2021
@justingrant justingrant changed the title Throw RangeError if there's an invalid offset string in ZonedDateTime-representing property bags Polyfill: Throw RangeError if there's an invalid offset string in ZonedDateTime-representing property bags Dec 13, 2021
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Dec 13, 2021
This PR focuses on unblocking `strictNullChecks` and
`strictPropertyInitialization` in ecmascript.ts and calendar.ts.
It's intended as a complement to @jens-ox's work to remove
`GetIntrinsic`.

This PR:
* Enables strictNullChecks: true and strictPropertyInitialization: true
  in tsconfig.json.
* Improves calendar.ts TS types (this was most of the work in this PR)
* Removes all unnecessary use of `any` throughout the polyfill
* Updates types of ecmascript.ts and fixes a number of type bugs
* Ports several proposal-temporal PRs:
  * tc39/proposal-temporal#1975 - Refactors to
    align ecmascript.mjs with spec text
  * tc39/proposal-temporal#1974 - Ensure that
    Temporal prototypes aren't writable
  * tc39/proposal-temporal#1976 - Throw
    RangeError if there's an invalid offset string in
    ZonedDateTime-representing property bags
* Fixes a few index.d.ts types
* Refactors a few types in intl.ts
* A handful of trivial type changes in other files (ecmascript.ts and
  calendar-ts were 95%+ of the work).

I'd like to split out the runtime behavior changes (mostly the ported
PRs above) into a smaller PR which should make it easier to review
changes that can actually break things at runtime. I also need to port
tests over from tc39/proposal-temporal#1976.

Once those are split out, this PR should be ready to review.
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Dec 13, 2021
This PR focuses on unblocking `strictNullChecks` and
`strictPropertyInitialization` in ecmascript.ts and calendar.ts.
It's intended as a complement to @jens-ox's work to remove
`GetIntrinsic`.

This PR:
* Enables strictNullChecks: true and strictPropertyInitialization: true
  in tsconfig.json.
* Improves calendar.ts TS types (this was most of the work in this PR)
* Removes all unnecessary use of `any` throughout the polyfill
* Updates types of ecmascript.ts and fixes a number of type bugs
* Ports several proposal-temporal PRs:
  * tc39/proposal-temporal#1975 - Refactors to
    align ecmascript.mjs with spec text
  * tc39/proposal-temporal#1974 - Ensure that
    Temporal prototypes aren't writable
  * tc39/proposal-temporal#1976 - Throw
    RangeError if there's an invalid offset string in
    ZonedDateTime-representing property bags
* Fixes a few index.d.ts types
* Refactors a few types in intl.ts
* A handful of trivial type changes in other files (ecmascript.ts and
  calendar-ts were 95%+ of the work).

I'd like to split out the runtime behavior changes (mostly the ported
PRs above) into a smaller PR which should make it easier to review
changes that can actually break things at runtime. I also need to port
tests over from tc39/proposal-temporal#1976.

Once those are split out, this PR should be ready to review.
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Dec 13, 2021
This PR focuses on unblocking `strictNullChecks` and
`strictPropertyInitialization` in ecmascript.ts and calendar.ts.
It's intended as a complement to @jens-ox's work to remove
`GetIntrinsic`.

This PR:
* Enables strictNullChecks: true and strictPropertyInitialization: true
  in tsconfig.json.
* Improves calendar.ts TS types (this was most of the work in this PR)
* Removes all unnecessary use of `any` throughout the polyfill
* Updates types of ecmascript.ts and fixes a number of type bugs
* Ports several proposal-temporal PRs:
  * tc39/proposal-temporal#1975 - Refactors to
    align ecmascript.mjs with spec text
  * tc39/proposal-temporal#1974 - Ensure that
    Temporal prototypes aren't writable
  * tc39/proposal-temporal#1976 - Throw
    RangeError if there's an invalid offset string in
    ZonedDateTime-representing property bags
  * tc39/proposal-temporal#1977 - Refactor
    and fix non-ISO calendars in polyfill
* Fixes a few index.d.ts types
* Refactors a few types in intl.ts
* A handful of trivial type changes in other files (ecmascript.ts and
  calendar-ts were 95%+ of the work).

I'd like to split out the runtime behavior changes (mostly the ported
PRs above) into a smaller PR which should make it easier to review
changes that can actually break things at runtime. I also need to port
tests over from tc39/proposal-temporal#1976.

Once those are split out, this PR should be ready to review.
Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

👍

polyfill/lib/zoneddatetime.mjs Outdated Show resolved Hide resolved
polyfill/test/duration.mjs Outdated Show resolved Hide resolved
@justingrant justingrant force-pushed the fix-ParseTimeZoneOffsetString-usage branch 2 times, most recently from aac20ea to c54df25 Compare December 15, 2021 05:42
Ensure that, per spec, a RangeError is thrown when an invalid offset is
passed to ParseTimeZoneOffsetString. Note that validation of the offset
in ISO strings is handled separately; this PR only fixes cases where
an offset is parsed on its own, e.g. when property bag inputs are used
in `ZonedDateTime#[with|from|equals|until|since|compare]` or as
options in `Duration#[add|subtract|compare|round|total]`. The problem
was also present in `TimeZone.from` and `ZonedDateTime#withTimeZone`
but was caught downstream so didn't fail any previous tests.

This commit also renames `ParseOffsetString` to
`ParseTimeZoneOffsetString` which is the AO name in the spec.

This commit also adds a new `ES.TestTimeZoneOffsetString` function
which checks to see if the string matches the offset regex. This is used
in cases where throwing on invalid offset strings is not desired.
@justingrant justingrant force-pushed the fix-ParseTimeZoneOffsetString-usage branch from c54df25 to c83a394 Compare December 15, 2021 05:48
@justingrant
Copy link
Collaborator Author

All review feedback is addressed, but the code has changed enough that I'd appreciate a fresh review. Thanks!

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Makes sense to me, thanks!

@ptomato ptomato merged commit 445079a into tc39:main Dec 15, 2021
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Dec 15, 2021
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Dec 15, 2021
justingrant added a commit to js-temporal/temporal-polyfill that referenced this pull request Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-spec-text PR can be ignored by implementors non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Polyfill usage of ParseTimeZoneOffsetString doesn't follow spec behavior for invalid offset strings
3 participants