Accept a module attribute as the private: option of a localized route - #26
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Before
A localized route whose
private:option is a module attribute:The router does not compile:
Problem
localize/1adds the locale to theprivate:(orassigns:) option, but only when that option is a literal map.put_value/3matches it.After
The same route compiles. A request to
/fr/sections/1has both values inconn.private:Details
Cause.
Localize.Routes.put_value/3has a clause forniland one for a literal map ({:%{}, meta, key_values}), nothing else.Fix. A third clause wraps any other expression in
Map.put/3, so the map is built at runtime, when the attribute has its value. The two existing clauses stay, so a literal map still merges at compile time.Tests.
test/support/router.exgets a route withprivate: @page_private;test/routes_test.exschecks that/fr/sections/1hassection: :docsand the localefrinconn.private. Without the fix the test router does not compile.Checks.
mix test(268 passed),mix format --check-formatted,mix compile --warnings-as-errors,mix credo --strict(one existing finding, unchanged).AI disclosure: AI models helped us find this issue, write the change, and review it.