fix(policy): reject bundle ids with a trailing/edge hyphen#545
fix(policy): reject bundle ids with a trailing/edge hyphen#545cblue0372-coder wants to merge 1 commit into
Conversation
The bundle-id rule's BUNDLE_RE used `[a-zA-Z][a-zA-Z0-9-]*` per label, which let a label end with a hyphen — so "com.foo.bar-" passed validation. Apple App Store Connect and Google Play both reject a bundle/application id whose label ends with (or doubles) a hyphen, so the linter was giving a false pass that the stores would later bounce. Tighten the pattern so hyphens are only allowed between alphanumerics within a label (`[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*`). All previously valid ids still pass; only genuinely store-invalid hyphen placements now fail. Add a vitest spec covering valid ids, internal hyphens, and the trailing/leading-hyphen and single-segment rejections.
Greptile SummaryTightens the
Confidence Score: 4/5Safe to merge — the regex change is correct and all existing valid bundle IDs continue to pass. The regex fix is logically sound and the five new tests confirm the intended behaviour. The only gap is that the doubled-hyphen case called out in the PR description has no corresponding spec, so a future regression there would be silent. bundle-id.test.ts — worth adding a doubled-hyphen test case to match the PR description's stated rejection rules. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[bundleId string] --> B{BUNDLE_RE.test}
B -- "passes" --> C{com.example.* ?}
C -- "yes" --> E[Finding: reserved namespace]
C -- "no" --> F[No findings ✓]
B -- "fails" --> D[Finding: not valid reverse-DNS]
subgraph BUNDLE_RE ["BUNDLE_RE pattern breakdown"]
direction LR
P1["^ [a-zA-Z]"] --> P2["[a-zA-Z0-9]*"] --> P3["(-[a-zA-Z0-9]+)*"] --> P4["(\\. label)+ $"]
end
Reviews (1): Last reviewed commit: "fix(policy): reject bundle ids with a tr..." | Re-trigger Greptile |
| it('rejects a single-segment id (not reverse-DNS)', () => { | ||
| const findings = lint('com'); | ||
| expect(findings.some((f) => /not valid reverse-DNS/.test(f.message))).toBe(true); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
The PR description explicitly calls out "doubled hyphen" (
com.foo--bar) as a case that stores reject, but there is no test covering it. The new regex does reject it correctly ((-[a-zA-Z0-9]+)* cannot consume --bar because the second character after the first - is another -), but a regression in the pattern would go unnoticed without a spec for this case.
| it('rejects a single-segment id (not reverse-DNS)', () => { | |
| const findings = lint('com'); | |
| expect(findings.some((f) => /not valid reverse-DNS/.test(f.message))).toBe(true); | |
| }); | |
| }); | |
| it('rejects a single-segment id (not reverse-DNS)', () => { | |
| const findings = lint('com'); | |
| expect(findings.some((f) => /not valid reverse-DNS/.test(f.message))).toBe(true); | |
| }); | |
| it('rejects a doubled hyphen within a label (com.foo--bar)', () => { | |
| const findings = lint('com.foo--bar'); | |
| expect(findings.some((f) => /not valid reverse-DNS/.test(f.message))).toBe(true); | |
| }); | |
| }); |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
5 similar comments
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
Problem
The bundle-id rule's
BUNDLE_REused[a-zA-Z][a-zA-Z0-9-]*per label, which let a label end with a hyphen — socom.foo.bar-passed validation. Apple App Store Connect and Google Play both reject a bundle/application id whose label ends with (or doubles) a hyphen, so the linter gave a false pass the stores would later bounce.Fix
Tighten the pattern so hyphens are only allowed between alphanumerics within a label:
[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*. All previously valid ids still pass; only genuinely store-invalid hyphen placements now fail. Adds a vitest spec (valid ids, internal hyphens, trailing/leading-hyphen and single-segment rejections).Tests
pnpm exec vitest run packages/policy/src/rules/bundle-id.test.ts→ 5 passed.