Skip to content

fix(isoDate): pad a bare-hour timeshift with a colon, not just zeros - #3143

Merged
Marsup merged 1 commit into
hapijs:masterfrom
yfwmaniish:fix/isodate-bare-hour-timeshift
Sep 2, 2026
Merged

Marsup merged 1 commit into
hapijs:masterfrom
yfwmaniish:fix/isodate-bare-hour-timeshift

Conversation

@yfwmaniish

Copy link
Copy Markdown
Contributor

Fixes #2434.

What

`internals.isoDate()` (`lib/types/string.js`) pads a bare-hour UTC timeshift like `+04` before handing the string to `Date()`:

```js
if (/.T.[+-]\d\d$/.test(value)) { // Add missing trailing zeros to timeshift
value += '00';
}
```

That produces `...+0400` β€” ISO 8601 basic-format offset β€” glued onto an otherwise extended-format string (`YYYY-MM-DDTHH:mm:ss`). ISO 8601 doesn't allow mixing the two; the correct extended-format offset is `...+04:00`.

This was flagged by @kanongil in review on #2421 (the PR that introduced the line): "You need to add the : as well to make it a proper extended iso date string. As it is, it breaks in Safari." The PR was merged before the fix landed, and #2434 was opened to track it but never addressed.

Also drops the leading .* in the trigger regex, per the same review thread (.test() doesn't need start-anchoring, so it was redundant).

Fix

```js
if (/T.*[+-]\d\d$/.test(value)) { // Add missing separator and trailing zeros to timeshift
value += ':00';
}
```

Testing

Node's own `Date` constructor parses `+0700` and `+07:00` identically, so a test asserting on Joi's converted output (`.toISOString()`) can't distinguish the bug from the fix β€” I confirmed this empirically before writing the test. Instead, the new test spies on the global `Date` constructor to assert the exact string Joi passes to it.

  • Negative control: reverted just the source fix, kept the test β€” it fails, showing the un-colonized string (`+0700`) reaching `Date()`. Restored.
  • Full suite: `lab` β€” 1824/1824 passing.
  • `eslint` clean on both changed files.

Copilot AI lite review requested due to automatic review settings September 1, 2026 08:08
internals.isoDate() pads a bare-hour UTC timeshift (e.g. "+04") before
handing the string to Date() by appending '00' directly, producing
"...+0400" instead of the ISO 8601 extended-format "...+04:00". Node's
own Date parser tolerates the malformed form, which is why this went
unnoticed, but it breaks stricter parsers (Safari) since ISO 8601
doesn't allow mixing basic-format offsets into an otherwise
extended-format string.

Flagged by a reviewer on hapijs#2421 (the PR that introduced this line) but
never addressed after merge; tracked since as hapijs#2434.

Also drops the leading `.*` in the trigger regex, per the same
review thread - matching doesn't require anchoring at the string
start, so it was redundant.

Since Node's Date constructor doesn't distinguish "+0700" from
"+07:00", a test asserting on Joi's converted output wouldn't catch
a regression here. The new test instead spies on the Date
constructor to assert the actual string produced.

Fixes hapijs#2434.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes string.isoDate() coercion so that ISO 8601 datetimes with a bare-hour UTC offset (e.g. +07) are normalized to the extended offset form (+07:00) before being parsed by Date(), avoiding invalid mixed-format offsets that break stricter parsers (notably Safari).

Changes:

  • Update internals.isoDate() normalization to append :00 (extended) instead of 00 (basic) when padding a bare-hour timeshift.
  • Simplify the trigger regex by removing the redundant leading .*.
  • Add a regression test that spies on the argument passed into Date() to ensure the colonized offset is used.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/types/string.js Fixes bare-hour offset padding to use +HH:00 (extended format) before calling new Date(value).
test/types/string.js Adds a regression test that temporarily replaces global.Date to assert the exact string passed to Date().

πŸ’‘ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Marsup Marsup self-assigned this Sep 2, 2026
@Marsup Marsup added the bug Bug or defect label Sep 2, 2026
@Marsup Marsup added this to the 18.2.6 milestone Sep 2, 2026
@Marsup Marsup added the security Issue with security impact label Sep 2, 2026
@Marsup
Marsup merged commit 8e98c07 into hapijs:master Sep 2, 2026
9 checks passed
@Marsup

Marsup commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks a lot. I'm also adding the security label, as it incidentally covers a vulnerability that was recently reported.

Marsup added a commit that referenced this pull request Sep 2, 2026
(cherry picked from commit cc81a74)
Marsup added a commit that referenced this pull request Sep 2, 2026
Marsup added a commit that referenced this pull request Sep 2, 2026
pull Bot pushed a commit to TheDegenerateDev5150/joi that referenced this pull request Sep 2, 2026
meta-codesync Bot pushed a commit to meta/memlab that referenced this pull request Sep 21, 2026
Summary:
Bumps [[ https://github.com/hapijs/joi | joi ]] from 17.13.4 to 17.13.7 in the memlab `website` package. The range picks up two prototype-pollution fixes plus an ISO date parsing fix.

== Notable changes ==

- **17.13.7** β€” `fix(isoDate)`: pad a bare-hour timeshift with a colon, not just zeros ([[ hapijs/joi#3143 | #3143 ]], backported in [[ hapijs/joi#3145 | #3145 ]])
- **17.13.6** β€” prevent `messages` prototype injection ([[ hapijs/joi#3139 | #3139 ]])
- **17.13.5** β€” prevent `__proto__` on renames ([[ hapijs/joi#3135 | #3135 ]])

== Commits ==

- [[ hapijs/joi@ed9d7cd | ed9d7cd ]] 17.13.7
- [[ hapijs/joi@f2729f7 | f2729f7 ]] Merge pull request [[ hapijs/joi#3145 | #3145 ]] from hapijs/backport/isodate-timeshift-v17
- [[ hapijs/joi@c43fc96 | c43fc96 ]] chore: add regression test for [[ hapijs/joi#3143 | #3143 ]]
- [[ hapijs/joi@115e7b5 | 115e7b5 ]] fix(isoDate): pad a bare-hour timeshift with a colon, not just zeros
- [[ hapijs/joi@850be1e | 850be1e ]] 17.13.6
- [[ hapijs/joi@9faeecc | 9faeecc ]] Merge pull request [[ hapijs/joi#3139 | #3139 ]] from hapijs/chore/backport-messages-proto
- [[ hapijs/joi@8d0b808 | 8d0b808 ]] fix: prevent messages proto injection
- [[ hapijs/joi@566e73f | 566e73f ]] 17.13.5
- [[ hapijs/joi@3f3907c | 3f3907c ]] Merge pull request [[ hapijs/joi#3135 | #3135 ]] from hapijs/chore/backport-rename-proto
- [[ hapijs/joi@172ecec | 172ecec ]] fix: prevent proto on renames

[[ hapijs/joi@v17.13.4...v17.13.7 | Full compare view: v17.13.4...v17.13.7 ]]

Pull Request resolved: #150

Differential Revision: D119235919

Pulled By: JacksonGL

fbshipit-source-id: 8b1427cfa5b65eab42a93ad713856feb7c57e1cc
daggerstuff added a commit to daggerstuff/pixelated that referenced this pull request Sep 24, 2026
* chore(deps): bump joi 17.13.4 -> 17.13.8

Replaces the production-patches bump from the deleted dependabot branch
(#6051): joi 17.13.5-17.13.8 carry the messages proto-injection guard
(hapijs/joi#3151) and the isoDate timeshift padding fix (hapijs/joi#3143).

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(deps): bump joi override pin to 17.13.8

The pnpm-workspace overrides pin joi: 17.13.4 was superseding the
manifest ^17.13.8 bump from the major-updates merge (#6053), making the
new version dead-letter and breaking the frozen lockfile check.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(deps): keep joi@17.13.4 resolvable for transitive pins

px-cli's install still resolves joi@17.13.4 (some tooling pins the exact
patch). Re-add its package + snapshot entries alongside 17.13.8.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Dagger <dagger@users.noreply.github.com>
Co-authored-by: Claude Code <noreply@anthropic.com>
Comment thread test/types/string.js

This comment was marked as spam.

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

Labels

bug Bug or defect security Issue with security impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix time regex

4 participants