Skip to content

feat(rewrite): validate rewrite rules at save time with helpful error messages#4453

Open
dave-atx wants to merge 6 commits into
miniflux:mainfrom
dave-atx:rule-validation
Open

feat(rewrite): validate rewrite rules at save time with helpful error messages#4453
dave-atx wants to merge 6 commits into
miniflux:mainfrom
dave-atx:rule-validation

Conversation

@dave-atx

Copy link
Copy Markdown
Contributor

This PR introduces a few quality-of-life improvements for working with content / URL / entry rewrite rules:

  • Rules are validated at save time on the add feed, edit feed, and settings screens. Malformed rules get a helpful error message and block saves.
  • Existing malformed rules get logged with a helpful error message at apply time.
  • The rules fields in the UI now have a monospaced font. all but the simple regex-based block/include filters are now <textarea>'s so they can be resized by the user in their browser during editing if desired.

I scratch this itch after spending an inordinate amount of time discovering that I had forgotten to double escape a backslash character in a content rewrite rule I was trying out. 🫠

The i18n outside of English is all LLM generated, so almost certainly is nonsensical for some languages.

Apologies for the size of the PR. The bulk of the file count is internationalization and tests.

dave-atx added 2 commits July 10, 2026 21:30
…itors

Reject malformed content- and URL-rewrite rules when a feed is created or
modified (REST API, Google Reader, OPML import, and both UI forms), while
warning-only at refresh so already-stored rules never break.

- New validator.IsValidRewriteRules mapping parse errors to localized keys;
  wired into feed create/modify and the UI subscription form. Also fill the
  UI feed-edit gap where RewriteRules was never sent for validation.
- Validate UrlRewriteRules everywhere and add the missing error key.
- Convert the scraper, content-rewrite, and URL-rewrite fields to
  monospaced, auto-growing, resizable textareas; give the filter, custom
  CSS/JS, and external-font-host fields the same monospaced treatment.
- English (en_US) strings for the new error keys; unit + API integration
  tests.
Machine-translated (unreviewed) strings for the content- and URL-rewrite
validation error keys across 22 locales.
@dave-atx

Copy link
Copy Markdown
Contributor Author

Changed the i18n's commit description to use feat(rewrite): as opposed to i18n:.

Make sure URL rewrite rules that don't call the correct "function" get
marked as invalid. For example, 'typo("find"|"replace")' is now marked
as invalid at save time.
@dave-atx

Copy link
Copy Markdown
Contributor Author

Also noticed that the URL Rewrite Rules field was not fully validating, so added the fix for that while this PR is in the area.

Specifically, it now flags missing 'functions' as invalid, e.g.:
replace("foo"|"bar") -> ❌
rewrite("foo"|"bar") -> ✔️

another one I found the hard way 😆 🫠

@fguillot fguillot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • After a rewrite validation error, updateFeed rerenders without setting hasProxyConfigured, so resubmitting silently stores FetchViaProxy=false.
  • replace("["|"x") passes validation even though its regex cannot compile, causing the rule to silently do nothing.

dave-atx added 3 commits July 17, 2026 23:25
The replace and replace_title rules compile their first argument as a
regular expression (regexp.Compile) at apply time, silently doing nothing
when the pattern is invalid. Flag those rules with regexArg in the
knownRules table and reject invalid patterns at save time via a new
RuleErrInvalidRegexp error, so users get immediate feedback instead of a
rule that quietly never matches.
Add error.feed_rewrite_rule_invalid_regex across all locales.
Machine-translated (unreviewed), except nan_Latn_pehoeji, which was
hand-derived from the sibling feed_rewrite_rule_* strings to match that
locale's existing vocabulary.
updateFeed re-renders edit_feed.html when validation fails but never set
hasProxyConfigured, so the 'fetch via proxy' checkbox vanished from the
re-rendered form for users with a proxy configured. Set it to match
feed_edit.go. Latent since the proxy option was introduced (2020).
@dave-atx

Copy link
Copy Markdown
Contributor Author

Updated to fix both of those issues.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants