Skip to content

Treat non-US reverse DNS prefixes as category roots - #8697

Open
timtebeek wants to merge 1 commit into
mainfrom
tim/root-category-tld-prefixes
Open

Treat non-US reverse DNS prefixes as category roots#8697
timtebeek wants to merge 1 commit into
mainfrom
tim/root-category-tld-prefixes

Conversation

@timtebeek

Copy link
Copy Markdown
Member

Symptom

A customer publishing a recipe library under a non-US reverse DNS prefix shows up in the marketplace nested under a meaningless top-level segment. uk.co.acme.recipes renders as Uk > Co > Acme > Recipes; de.example.recipes renders as De > Example > Recipes.

This happens because a package segment with no matching category descriptor gets a synthetic category built from its capitalized name. com, org, io, ai, tech and software already have root: true descriptors in core-categories.yml — everything else does not.

Fix

Add root: true category descriptors to rewrite-core/src/main/resources/META-INF/rewrite/core-categories.yml. A root descriptor is not rendered as a node and its children are hoisted, which is enforced in CategoryTree.getCategories() and in YamlRecipeBundleReader.inferCategoriesFromName().

Generic TLDs:

net edu gov mil int dev app cloud us eu

Country code TLDs:

uk de nl fr ch at be dk se no fi ie es it pl cz au nz ca jp cn in kr sg hk br mx za il ae

Second level domains, rooted in addition to their parent — without these, dropping "Uk" only promotes "Co" to the top level:

uk.co uk.org uk.ac uk.gov uk.me jp.co jp.ne jp.or au.com au.net au.org br.com za.co nz.co il.co in.co kr.co

Matching is anchored at the full partial package (uk.co, not any segment named co), so short entries that are also English words are only ever consumed in first position. Nothing that could plausibly be a category in its own right is rooted.

no is quoted, since YAML 1.1 would otherwise resolve it to a boolean.

Tests

  • CategoryTreeTest#reverseDnsPrefixesAreCategoryRootsuk.co.acme and de.example are top-level categories; uk, uk.co and de are not.
  • YamlRecipeBundleReaderTest#twoSegmentReverseDnsPrefixesAreOmittedFromTheInferredPathuk.co.acme.recipes.FindAndReplace infers Acme > Recipes.
  • YamlRecipeBundleReaderTest#singleSegmentReverseDnsPrefixesAreOmittedFromTheInferredPathde.example.recipes.SomeRecipe infers Example > Recipes.

All three fail against the current core-categories.yml and pass with it.

A recipe library published under, say, `uk.co.acme.recipes` had no matching
category descriptor for `uk`, so the marketplace synthesized one and rendered
the library under a meaningless "Uk" > "Co" > "Acme" path. Marking these
prefixes as roots drops them from the displayed path, both in `CategoryTree`
and in the category inference `YamlRecipeBundleReader` does from a recipe name.

Second level domains (`uk.co`, `jp.co`, `au.com`, ...) are rooted alongside
their parent, otherwise dropping "Uk" only promotes "Co" to the top level.
Matching is anchored at the full partial package, so a segment named `co`
deeper in a package is unaffected.
@timtebeek

Copy link
Copy Markdown
Member Author
   FAIL  test/javascript/templating/control-parentheses-capture.test.ts > a capture that is a whole ControlParentheses > with expression
  AssertionError: expected undefined to be defined
   ❯ findFirst test/javascript/templating/control-parentheses-capture.test.ts:46:19
       44|     };
       45|     await visitor.visit(cu, new ExecutionContext());
       46|     expect(found).toBeDefined();
         |                   ^
       47|     return found!;
       48| }
   ❯ matchFirst test/javascript/templating/control-parentheses-capture.test.ts:52:28
   ❯ test/javascript/templating/control-parentheses-capture.test.ts:85:16

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant