scraper.go 724 B

1234567891011121314151617181920212223
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package validator // import "miniflux.app/v2/internal/validator"
  4. import (
  5. "github.com/andybalholm/cascadia"
  6. "miniflux.app/v2/internal/locale"
  7. )
  8. // IsValidScraperRules validates scraper rules, which are a CSS selector. The
  9. // scraper silently extracts nothing when the selector does not compile, so an
  10. // invalid one is rejected at save time instead.
  11. func IsValidScraperRules(rules string) *locale.LocalizedError {
  12. if rules == "" {
  13. return nil
  14. }
  15. if _, err := cascadia.Compile(rules); err != nil {
  16. return locale.NewLocalizedError("error.feed_invalid_scraper_rule", err.Error())
  17. }
  18. return nil
  19. }