Skip to content

fix(access): resolve country ratings written with a dash, such as SE-7 - #4505

Open
Rhainland wants to merge 1 commit into
Silo-Server:mainfrom
Rhainland:fix/4495-dash-country-rating
Open

Rhainland wants to merge 1 commit into
Silo-Server:mainfrom
Rhainland:fix/4495-dash-country-rating

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #4495
Related issue: N/A
Validation tasks: none (kids filtering in #1180 C1 and #1181 C1 is reachable but not yet run)

Other clients: Apple N/A (no client-visible change); Android N/A (no client-visible change); Roku N/A (no client-visible change)

Silo understood a country code on a content rating only when a colon separated it: SE:7 resolved to age 7. Jellyfin writes the same rating as SE-7 or DE-16, and those strings resolved to nothing. Silo stores an unreadable rating as age 99, so every profile with a content-rating ceiling lost these titles, whatever access.unrated_content was set to. A content_rating rule could not match them either. Anyone whose NFO files came from Jellyfin with a non-US certification country was affected.

Approach

access.Normalize first tries the whole string as before. If that fails, it removes a leading country code and dash and resolves the rest. Trying the whole string first keeps TV-MA, PG-13, NC-17, MA-15+ and UA-13+ unchanged.

The dash form is stricter than the colon form, because a string that used to be hidden must not start resolving to a younger age than it means:

  • The code must be a country: one of the aliases in countrySystems, or a region golang.org/x/text/language treats as a country. ZZ-7 stays unrecognized.
  • TV, PG and NC never count as countries (Tuvalu, Papua New Guinea, New Caledonia), so PG-15 stays unrecognized instead of becoming 15.
  • The rest is read only in that country's own ladder or as a bare age. It is never looked up in another country's ladder, so NZ-M (16 in New Zealand) does not take Australia's M (15), and GB-AA does not take Mexico's all-ages AA.
  • If the rest contains non-ASCII letters or digits, it is refused. Token folding would drop them and could leave a bare age the label never meant (HK-第3級 would become 3). Non-ASCII punctuation is fine, so FR-–16 resolves to 16.

Two things are left out on purpose:

  • Word rungs such as SE-Btl and localized text such as SE-Från 7 år stay unrecognized. The issue describes these as a missing capability, not a parsing defect.
  • The frozen backfill migration is unchanged, and no new migration rewrites old rows. A title already stored as SE-7 keeps age 99, which is the restrictive direction, until its metadata is refreshed or the file changes. A plain rescan of unchanged files does not rewrite the age.

Validation

  • Table rows in internal/access for the dash form, the dashed rungs it must keep, and the strings that must stay unrecognized. They failed before the fix.
  • go build ./..., gofmt, go mod tidy -diff, go vet ./..., make lint-changed, make lint-router-recovery: clean.
  • make test-go: passes.
  • Local build with synthetic movies whose NFO <mpaa> holds each value, checked before and after on the same database (below).

Evidence

No screen changes, but the catalog changes which titles a restricted profile sees, so here are API results from a local build. A movie library holds synthetic titles with the NFO ratings shown. A second profile on the account has max_content_rating PG, then 15. GET /api/v2/catalog?library_id=1 was called with each profile's X-Profile-ID, and content_rating_age was read from media_items.

Before, on origin/main at e8de111:

== profile kid (PG)
Colon Seven	SE:7

 title        | content_rating | content_rating_age
 Colon Seven  | SE:7           |  7
 Control PG13 | PG-13          | 13
 Control TVMA | TV-MA          | 17
 Dash Fifteen | SE-15          | 99
 Dash German  | DE-16          | 99
 Dash Seven   | SE-7           | 99

After, on this branch, with the same database after a library metadata refresh (three more titles were added by a scan):

== profile kid (PG)
Colon Seven	SE:7
Dash Seven	SE-7
== profile kid (15)
Colon Seven	SE:7
Control PG13	PG-13
Dash Eleven	SE-11
Dash Fifteen	SE-15
Dash Seven	SE-7

 title        | content_rating | content_rating_age
 Colon Seven  | SE:7           |  7
 Control PG13 | PG-13          | 13
 Control TVMA | TV-MA          | 17
 Dash Eleven  | SE-11          | 11
 Dash Fifteen | SE-15          | 15
 Dash French  | FR-–16         | 16
 Dash German  | DE-16          | 16
 Dash Kiwi    | NZ-M           | 99
 Dash Seven   | SE-7           |  7
 Dash Ukraine | UA-18          | 18

Risks

  • Ratings that used to store 99 can now store a real age, which can widen what a restricted profile sees. That is the purpose of the fix, and the rules above limit it to strings whose age is unambiguous.
  • US-NR and similar now count as unrated rather than unreadable, the same as US:NR, so access.unrated_content decides whether ceilinged profiles see them.
  • Existing rows change only when their metadata is refreshed.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code (via T3 Code); Codex CLI for code review
  • Tool(s): Claude Code, Codex CLI
  • Model(s): claude-opus-5-5; gpt-6.2-sol, gpt-6.2-astra, claude-fable-5-2 (code review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: Four rounds of multi-model review (gpt-6.2-sol and gpt-6.2-astra through Codex CLI, Claude Opus 5.5 and Claude Fable 5.2 as subagents; round four was Opus only) on correctness, repository standards and the issue's spec. Round one found three problems: the dash path fell back to other countries' ladders (NZ-M became 15, GB-AA became 0), any two letters counted as a country (ZZ-7, and DEU-16 was missed), and two comments were stale. All three were fixed. Round two found two more: localized labels could fold to a bare age (HK-第3級), and UA-18 and MA-16 were refused needlessly. Both were fixed. Round three noted that the ASCII guard refused FR-–16, so the guard now rejects only non-ASCII letters. Round four found that a full-width digit (DE-16) would fold to age 1, so the guard also rejects non-ASCII digits. Dismissed: AU-PG resolving to 8, which matches the existing AU:PG and PG; IE-12A staying unrecognized because no Irish ladder exists yet, which fails in the restrictive direction; and inputs no tool writes, such as NR-17.

Note

Resolve dashed country rating prefixes like SE-7 in access.Normalize

  • Normalize in rating.go now falls back to parsing dashed country prefixes (e.g. SE-7) when the full input does not resolve, using the country's own systems or a bare age.
  • Adds cutDashedCountryPrefix and a shared cutCountryCode parser; dashed prefixes that open rating rungs (via dashedRatingPrefixes) are excluded from country-code interpretation, as are remainders with non-ASCII alphanumerics that canonicalization would drop.
  • resolveRatingToken gains a crossSystem flag so dashed-prefix lookups stay within the country's systems instead of crossing into another ladder.
  • Risk: rows backfilled before this change keep the unrecognized age until the item is next written, per the updated StoredRating documentation.

Macroscope summarized eb50d42.

Jellyfin stores a country-coded certification as SE-7 or DE-16, while
Normalize only understood the Kodi/Radarr colon form. The dash form
folded to an unknown token, stored the unrecognized age and hid the
title from every profile with a content-rating ceiling.

Normalize now retries a string that did not resolve with a leading
country code and dash removed. The whole string is tried first, and TV,
PG and NC never count as countries, so dashed rungs such as TV-MA,
PG-13 and NC-17 keep their meaning. The code must be a country, and the
remainder is read only in that country's own ladder or as a bare age,
so NZ-M does not borrow Australia's M. A remainder with letters the
token folding would drop (HK-第3級) is refused rather than read as a
bare age.
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 18, 2026
@silo-kody

silo-kody Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Rating normalization now recognizes dashed country-prefixed ratings after existing resolution fails. The fallback validates the country prefix and restricts lookup to that country’s systems and bare ages. Tests cover supported ratings and ambiguous or malformed inputs.

Changes: Country-prefixed rating resolution

Layer / File(s) Summary
Country-prefix parsing safeguards
internal/access/rating.go
A shared parser handles colon and dash separators. Dashed prefixes must match recognized country codes or aliases, and the parser rejects rating-like prefixes and remainders containing non-ASCII letters or numbers.
Dashed-prefix fallback and validation
internal/access/rating.go, internal/access/rating_test.go
Normalize tries dashed-prefix resolution after existing resolution fails. The fallback checks the specified country's systems and bare ages, but not other systems' ladders. Tests cover supported ratings and rejected inputs. The StoredRating comment notes that the frozen backfill does not recognize dashed country forms.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Normalize
  participant splitCountryPrefix
  participant resolveRating
  participant resolveRatingToken
  Normalize->>splitCountryPrefix: Parse dashed country prefix after existing resolution fails
  Normalize->>resolveRating: Resolve remainder with cross-system lookup disabled
  resolveRating->>resolveRatingToken: Check country-specific systems and bare ages
Loading

Suggested labels: bug, go

Suggested reviewers: quick104

Merge Risk: Minimal · up to eb50d

This change lets dash-separated country ratings such as SE-7 resolve to an age, so they are no longer treated as unrated for content-rating ceilings and rules. Existing ratings keep their current resolution. Stored rows change only after a metadata refresh. No merge-blocking risk was identified.

Security architecture risk: Minimal · up to eb50d

The change recognizes additional country-prefixed ratings while preserving existing matches and rejecting ambiguous or unsafe interpretations. The inspected paths show no introduced authorization bypass. Existing titles can remain hidden until their rating age is rewritten.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The behavioral reach includes titles carrying newly recognized dashed labels and profiles whose maturity ceilings evaluate those titles. Shared normalization can also change configured routing-condition matches; the effect is not limited to one profile.

Trust Boundaries and Controls

  • observed — The new metadata-to-age interpretation rejects TV, PG, and NC as dashed country prefixes, validates other countries, and refuses non-ASCII letters or numbers that canonicalization would discard. Dashed remainders cannot borrow another country's ladder, preventing the inspected NZ-M and GB-AA under-classification cases.

Resilience and Maintainability Implications

  • inferred — During partial adoption, untouched age-99 rows remain more restrictive than freshly classified rows. The inspected raw-rating and derived-age writes preserve their pairing, so interrupted or competing writes do not introduce a new split-field authorization state.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: country-coded ratings written with a dash (e.g., SE-7) now resolve in access.Normalize. The raw summary and objectives confirm the dash fallback, the country-code rest…
Description check Passed The description covers the problem (dash-separated country ratings such as SE-7 resolve to nothing and are stored as age 99), the approach in access.Normalize, the restrictions on the dash form, valid…
Linked Issues check Passed Directly linked issue #4495 requires that a country-coded rating written with a dash, such as SE-7, resolve to the same age as the colon form SE:7. The PR adds a dash-prefix fallback in access.Normali…
Out of Scope Changes check Passed The changes are limited to internal/access/rating.go and internal/access/rating_test.go. The rating.go change adds the dash-prefix fallback, a shared country-prefix splitter for both separators, the c…
Full details: Title check

Explanation

The title names the main change: country-coded ratings written with a dash (e.g., SE-7) now resolve in access.Normalize. The raw summary and objectives confirm the dash fallback, the country-code restrictions, and the rating tests, so the title matches the changeset. It is specific and concise, and it uses the conventional prefix format.

Full details: Description check

Explanation

The description covers the problem (dash-separated country ratings such as SE-7 resolve to nothing and are stored as age 99), the approach in access.Normalize, the restrictions on the dash form, validation steps, before-and-after evidence, and risks. It relates directly to the changeset, so this lenient check passes.

Full details: Linked Issues check

Explanation

Directly linked issue #4495 requires that a country-coded rating written with a dash, such as SE-7, resolve to the same age as the colon form SE:7. The PR adds a dash-prefix fallback in access.Normalize (internal/access/rating.go). It tries the full string first, then removes a recognized leading country code and dash, and resolves the remainder in that country's ladder or as a bare age. The change covers any country code that the code recognizes, not only Sweden, which matches the issue's separator-defect scope. Table tests in internal/access/rating_test.go cover the dash form, the dashed rungs that must keep working (TV-MA, PG-13, NC-17, MA-15+, UA-13+), and the strings that must stay unrecognized. The PR description also reports before and after API results: SE-7, SE-11, SE-15, DE-16 and UA-18 now store a real age. The issue states that word rungs (SE-Btl) and localized labels (SE-Från 7 år) are a separate missing capability, not part of this parsing defect. The PR leaves them unrecognized on purpose, so their absence does not fail this requirement. The PR does not change the frozen backfill migration. Existing rows update only on metadata refresh, which the issue does not require to be automatic. Assessment is based on the whole-PR summary and the reviewed code and test descriptions. No additional repository inspection was made.

Full details: Out of Scope Changes check

Explanation

The changes are limited to internal/access/rating.go and internal/access/rating_test.go. The rating.go change adds the dash-prefix fallback, a shared country-prefix splitter for both separators, the country-code and non-ASCII guards, and comments that document the frozen backfill behavior. The test change adds TestNormalizeCountryPrefix. Each change serves the dash-form requirement in #4495. The PR does not add a migration, does not rewrite stored rows, and does not add word-rung or localized-label support, which the PR and issue both mark as out of scope. The PR notes a visibility side effect: US-NR now counts as unrated rather than unreadable. This follows from the same Normalize change and is documented in the PR risks section, so it is a consequence of the fix and not unrelated work.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 53c00100-fea0-4297-a53f-a29f14e774fb
Commits

Reviewing files that changed from the base of the PR and between e8de111 and eb50d42.

Files selected for processing: 2

  • internal/access/rating.go
  • internal/access/rating_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: compat Breaks a supported client or server path priority: P2 Limited scope, workaround exists, or polish labels Nov 18, 2026
Comment thread internal/access/rating.go
Comment on lines +285 to +286
if rest, systems, cut := cutDashedCountryPrefix(raw); cut {
return resolveRating(rest, systems, false)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

Existing dashed ratings remain hidden by stale stored ages

Items rated SE-7 or DE-16 retain a stored age of 99, so maturity-filtered catalog queries still hide them despite the change to Normalize. Recompute affected ages during upgrade and refresh their episode catalog copies.

Prompt for LLM
File internal/access/rating.go, lines 285-286:

Existing dashed ratings remain hidden by stale stored ages

Existing `SE-7` and `DE-16` items retain the previously stored age of 99, so maturity-filtered catalog queries continue hiding them even though `Normalize` now recognizes their ratings. Recompute persisted ages for affected rows during upgrade and refresh their episode catalog copies.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

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

Labels

bug Something isn't working go Pull requests that update go code impact: compat Breaks a supported client or server path priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] A Swedish certification written with a dash (SE-7) resolves to unrated, while SE:7 resolves to age 7

1 participant