Skip to content

fix(x-robots-tag): allow max-snippet -1 (no snippet-length limit) - #1227

Merged
ferhatelmas merged 1 commit into
supabase:masterfrom
samarth70:fix/x-robots-tag-max-snippet-allow-minus-one
Jul 15, 2026
Merged

ferhatelmas merged 1 commit into
supabase:masterfrom
samarth70:fix/x-robots-tag-max-snippet-allow-minus-one

Conversation

@samarth70

Copy link
Copy Markdown
Contributor

Problem

The max-snippet X-Robots-Tag validator (src/storage/validators/x-robots-tag.ts) rejects -1:

case 'max-snippet': {
  const num = parseInt(ruleValue, 10)
  if (isNaN(num) || num < 0) {   // rejects -1

Per the robots meta tag spec, max-snippet: -1 means "no snippet-length limit" and is a valid value (alongside 0 and any positive integer) — in fact it's the recommended default (max-snippet:-1, max-image-preview:large, max-video-preview:-1). The sibling max-video-preview case in the same file already handles this correctly with num < -1; max-snippet was an inconsistent oversight.

So a user setting the spec-recommended X-Robots-Tag: max-snippet:-1 gets a 400 InvalidXRobotsTag error.

Fix

Loosen the guard to num < -1 and align the error message with max-video-preview ("must be a number >= -1"). Update the existing negative-value test to -5 (still rejected) and add a case asserting -1 is accepted.

Tests

src/storage/validators/x-robots-tag.test.ts: adds "accepts max-snippet: -1", keeps "throws below -1" (-5) and "throws for non-numeric" (abc).

Note on verification: I confirmed the edited validator logic directly (-1 accepted; -5/abc still rejected; max-video-preview unchanged), but couldn't run the full vitest suite locally — supabase/storage doesn't install on Windows (fs-xattr is os: "!win32" and the repo requires Node ≥ 24). The change is a one-line guard + test, so CI should confirm.

@samarth70
samarth70 requested a review from a team as a code owner July 13, 2026 23:59
Comment thread src/storage/validators/x-robots-tag.ts Resolved
@ferhatelmas
ferhatelmas force-pushed the fix/x-robots-tag-max-snippet-allow-minus-one branch from 13f6926 to 416cb1a Compare July 14, 2026 12:49
@coveralls

coveralls commented Jul 14, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 29400745661

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.1%) to 79.479%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 1 of 1 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 12702
Covered Lines: 10548
Line Coverage: 83.04%
Relevant Branches: 7385
Covered Branches: 5417
Branch Coverage: 73.35%
Branches in Coverage %: Yes
Coverage Strength: 423.73 hits per line

💛 - Coveralls

@ferhatelmas
ferhatelmas force-pushed the fix/x-robots-tag-max-snippet-allow-minus-one branch from 416cb1a to 3e30a2c Compare July 15, 2026 08:00
The max-snippet validator rejected -1 (guard was num < 0), but per the robots
meta spec -1 means 'no snippet-length limit' and is a valid value (alongside 0
and any positive integer) — it's the recommended default. The sibling
max-video-preview case already uses num < -1 correctly; max-snippet was an
inconsistent oversight.

Loosen the guard to num < -1 and align the error message with max-video-preview
('must be a number >= -1'). Update the existing negative-value test to -5 and
add a case asserting -1 is accepted.
@ferhatelmas
ferhatelmas force-pushed the fix/x-robots-tag-max-snippet-allow-minus-one branch from 3e30a2c to 8e218c8 Compare July 15, 2026 08:25
@ferhatelmas
ferhatelmas merged commit 9434eb7 into supabase:master Jul 15, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants