GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: avoid crash when contributors tag is at the start of a file by davidpavlovschi · Pull Request #521 · all-contributors/cli

Conversation

@davidpavlovschi

@davidpavlovschi davidpavlovschi commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What:

Fixes the crash in all-contributors add/generate when the file being updated starts immediately with the list tag (no title or any content before it — the p5.js CONTRIBUTORS.md case from #376). As reported in the issue:

RangeError: Invalid count value: -1
    at String.repeat (<anonymous>)
    at .../dist/generate/index.js:19:186
    at module.exports (.../dist/generate/index.js:75:78)

Closes #376

Why:

In injectListBetweenTags (src/generate/index.js), nbSpaces is derived from lastIndexOf('\n', startOfOpeningTagIndex). When the tag is at the very start of the file, lastIndexOf returns -1, Math.max(0, …) clamps it to 0, so nbSpaces is 0 and ' '.repeat(nbSpaces - 1) throws RangeError: Invalid count value: -1. For a tag at column 0 on any later line, nbSpaces is 1 and the same expression is repeat(0) — so a zero indent is exactly the established behaviour for an unindented tag; only the file-start position crashes.

How:

Clamp the count: ' '.repeat(Math.max(0, nbSpaces - 1)). No existing output changes — every current snapshot passes untouched. The sibling badge path (replaceBadge, ' '.repeat(nbSpaces)) subtracts nothing and cannot go negative, so it is deliberately left alone.

Added a regression test in src/generate/__tests__/index.js that runs generate() over content whose first byte is <!-- ALL-CONTRIBUTORS-LIST:START --> and asserts a table is injected. It fails on main (reproducing the same RangeError at the String.repeat frame, seen from the test runner rather than the built dist/ bundle) and passes with this change.

Verified locally with npm ci: npx vitest run — 15 files, 114 tests, all passing, no snapshot updates; npx eslint src/generate and npx prettier --check clean.

Checklist:

  • Documentation N/A
  • Tests
  • Ready to be merged
  • Added myself to contributors table N/A

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JimMadge reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@davidpavlovschi
fix: avoid crash when contributors tag is at the start of a file
7def00e
When a file begins with the ALL-CONTRIBUTORS-LIST:START tag, nbSpaces is 0 and
' '.repeat(nbSpaces - 1) throws RangeError: Invalid count value: -1.

Clamp the indent to zero, which matches the width already produced for a tag
sitting at column 0 on any later line.

Closes all-contributors#376
@JimMadge
JimMadge requested a review from a team August 4, 2026 13:25
JimMadge
JimMadge reviewed Aug 4, 2026
View reviewed changes

@JimMadge JimMadge left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good spot @davidpavlovschi 🎉.

The code in this section is a little hard to understand. I think this is about retaining any indent that the contributors table had before.

I haven't figured out why there is a need for the -1 though 🤔. I'm wondering if there is a better way to handle all cases. This fixes the issue though so I think we can get it merged without worrying about rewriting the entire function.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/generate/index.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@davidpavlovschi
refactor: clamp nbSpaces at the computation instead of the use site
ac41330
Fold the -1 and the Math.max(0, ...) into the nbSpaces calculation so the
value can never be negative, and keep a plain ' '.repeat(nbSpaces) at the
use site, as suggested in review.
JimMadge
JimMadge approved these changes Aug 6, 2026
View reviewed changes

@JimMadge JimMadge left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good, thanks @davidpavlovschi 🙏 🎉

@lwasser how is the release prep going? Can we get this fix in (or following shortly in a patch release)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@JimMadge
JimMadge merged commit 34d63ca into all-contributors:main Aug 6, 2026
6 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@JimMadge

JimMadge commented Aug 6, 2026

Copy link
Copy Markdown
Member

@allcontributors please add @davidpavlovschi for code

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@allcontributors allcontributors Bot mentioned this pull request Aug 6, 2026
docs: add davidpavlovschi as a contributor for code #525
Merged
@allcontributors

allcontributors Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@JimMadge

I've put up a pull request to add @davidpavlovschi! 🎉

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lwasser lwasser mentioned this pull request Jul 1, 2026
chore(main): release 6.27.0 #483
Closed
This was referenced Oct 23, 2026
chore(main): release 6.27.0 #581
Closed
chore(release): release 7.0.0 #583
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JimMadge JimMadge JimMadge approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Crash when adding contributors and there is no content before the all contributors comment tag

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@davidpavlovschi @JimMadge
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.