Repository navigation
[pull] main from miniflux:main - #340
Merged
Merged
Conversation
The Language fields added for Atom 1.0 and 0.3 feeds and entries used the struct tag `xml:"lang,attr"`, which encoding/xml matches against a lang attribute from any namespace, with the last one in document order winning. A feed carrying e.g. foo:lang="zz" after xml:lang="fr" would be stored with language "zz". Qualify the tags with the XML namespace so only xml:lang matches. As a side effect, a bare non-standard lang attribute is now ignored instead of being treated as the feed language. Also document each Language field and add regression tests covering foreign-namespace and unqualified lang attributes, plus first coverage of xml:lang parsing for Atom 0.3.
Per the XML specification, xml:lang applies to the whole subtree it is declared on, so an Atom entry without its own xml:lang attribute takes the language declared on the feed element. The parser previously left such entries with an empty language, and only the web UI compensated with a template-level fallback; API consumers reading entries.language saw an empty value even when the feed declared one. Apply the fallback in the Atom 1.0 and 0.3 adapters so the inherited value is persisted and exposed everywhere. Known limitation: an explicit xml:lang="" on an entry, which the spec defines as undefining the language for that subtree, cannot be distinguished from an absent attribute with a plain string field and therefore inherits as well.
NormalizeLanguage lived in the model package but is a parse-time input-cleaning helper: all of its callers are the feed-format adapters, nothing in model uses it, and as a free function it never enforced a model invariant. Parse-time normalization helpers belong under internal/reader alongside date, sanitizer, and urlcleaner. Move it to a new internal/reader/language package and rename it to Normalize so call sites read language.Normalize(...). No behaviour change.
Feed-declared language values were persisted and rendered with no
charset or length restriction. Normalize now rejects values longer
than 50 bytes or containing characters outside [a-z0-9-], keeping
control characters, NUL bytes (which Postgres rejects, failing the
feed refresh), and oversized values out of the database and the HTML
lang attribute. Invalid values are rejected rather than stripped,
since stripping could assemble a wrong tag ("fr, en" -> "fren").
Lower-casing is ASCII-only and done in the same pass as the charset
check: Unicode case folding maps some non-ASCII characters to ASCII
(e.g. the Kelvin sign U+212A to "k"), laundering input the filter
should reject into apparently valid tags.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )