8000 [pull] main from miniflux:main by pull[bot] · Pull Request #263 · suhaoGe/miniflux · GitHub
[go: up one dir, main page]

Skip to content
8000
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/debian_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- 'packaging/debian/**' # Only run on changes to the debian packaging files
jobs:
test-packages:
if: (github.event_name == 'schedule' && github.repository_owner == 'miniflux' )
if: (github.event_name == 'schedule' && github.repository_owner == 'miniflux')
|| github.event_name == 'pull_request'
name: Test Packages
runs-on: ubuntu-latest
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
if-no-files-found: error
retention-days: 3
publish-packages:
if: github.event_name == 'push'
if: github.event_name == 'push' && github.repository_owner == 'miniflux'
name: Publish Packages
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/rpm_packages.yml
8000
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ on:
- '.github/workflows/rpm_packages.yml'
jobs:
test-package:
if: github.event_name == 'schedule' || github.event_name == 'pull_request'
if: (github.event_name == 'schedule' && github.repository_owner == 'miniflux')
|| github.event_name == 'pull_request'
name: Test Packages
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -43,7 +44,7 @@ jobs:
if-no-files-found: error
retention-days: 3
publish-package:
if: github.event_name == 'push'
if: github.event_name == 'push' && github.repository_owner == 'miniflux'
name: Publish Packages
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,9 @@ func startDaemon(store *storage.Storage) {
slog.Debug("No HTTP servers to shut down.")
}

slog.Debug("Shutting down worker pool...")
pool.Shutdown()
slog.Debug("Worker pool shut down.")

slog.Debug("Process gracefully stopped")
}
5 changes: 5 additions & 0 deletions internal/reader/sanitizer/sanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ var (
"bandcamp.com": {},
"cdn.embedly.com": {},
"dailymotion.com": {},
"framatube.org": {},
"open.spotify.com": {},
"player.bilibili.com": {},
"player.twitch.tv": {},
Expand Down Expand Up @@ -291,6 +292,10 @@ func filterAndRenderHTML(buf *strings.Builder, n *html.Node, parsedBaseUrl *url.

htmlAttributes, hasAllRequiredAttributes := sanitizeAttributes(parsedBaseUrl, tag, n.Attr, sanitizerOptions)
if !hasAllRequiredAttributes {
if tag == "iframe" {
// A blocked iframe should not have its inner content rendered.
return nil
}
// The tag doesn't have every required attributes but we're still interested in its content
return filterAndRenderHTMLChildren(buf, n, parsedBaseUrl, sanitizerOptions, depth-1)
}
Expand Down
44 changes: 44 additions & 0 deletions internal/reader/sanitizer/sanitizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package sanitizer // import "miniflux.app/v2/internal/reader/sanitizer"

import (
"fmt"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -397,6 +398,18 @@ func TestInvalidIFrame(t *testing.T) {
}
}

func TestBlockedIFrameWithChildElements(t *testing.T) {
config.Opts = config.NewConfigOptions()

input := `<iframe src="http://example.org/"><p>test</p></iframe>`
expected := ``
output := sanitizeHTMLWithDefaultOptions("http://example.com/", input)

if expected != output {
t.Errorf(`Wrong output: %q != %q`, expected, output)
}
}

func TestSameDomainIFrame(t *testing.T) {
config.Opts = config.NewConfigOptions()

Expand All @@ -421,6 +434,37 @@ func TestInvidiousIFrame(t *testing.T) {
}
}

func TestIFrameAllowList(t *testing.T) {
config.Opts = config.NewConfigOptions()

allowedDomains := []string{
"bandcamp.com",
"cdn.embedly.com",
"dailymotion.com",
"framatube.org",
"open.spotify.com",
"player.bilibili.com",
"player.twitch.tv",
"player.vimeo.com",
"soundcloud.com",
"vk.com",
"w.soundcloud.com",
"youtube-nocookie.com",
"youtube.com",
}

for _, domain := range allowedDomains {
t.Run(domain, func(t *testing.T) {
input := fmt.Sprintf(`<iframe src="https://%s/video/test"></iframe>`, domain)
output := sanitizeHTMLWithDefaultOptions("http://example.com/", input)

if !strings.Contains(output, "<iframe") {
t.Errorf(`iframe from %q should be allowed, got: %q`, domain, output)
}
})
}
}

func TestCustomYoutubeEmbedURL(t *testing.T) {
os.Setenv("YOUTUBE_EMBED_URL_OVERRIDE", "https://www.invidious.custom/embed/")

Expand Down
10 changes: 2 additions & 8 deletions internal/timezone/timezone.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func Convert(tz string, t time.Time) time.Time {
t.Nanosecond(),
userTimezone,
)
} else if t.Location() != userTimezone {
} else if t.Location().String() != userTimezone.String() {
return t.In(userTimezone)
}

Expand Down Expand Up @@ -521,11 +521,5 @@ func IsValid(timezone string) bool {

// AvailableTimezones returns an iterator over supported timezone names.
func AvailableTimezones() iter.Seq[string] {
return func(yield func(string) bool) {
for _, tz := range timezones {
if !yield(tz) {
return
}
}
}
return slices.Values(timezones)
}
17 changes: 15 additions & 2 deletions internal/timezone/timezone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ func TestConvertTimeWithIdenticalTimezone(t *testing.T) {
}
}

func TestConvertTimeWithEquivalentTimezone(t *testing.T) {
tz := "UTC"
// FixedZone creates a distinct pointer that has the same name as the cached location.
// The old pointer comparison would treat these as different, calling t.In() unnecessarily.
loc := time.FixedZone("UTC", 0)
input := time.Date(2024, 6, 15, 12, 0, 0, 0, loc)
output := Convert(tz, input)

if output.Location() != loc {
t.Fatal("Convert replaced the location even though timezone names match")
}
}

func TestConvertPostgresDateTimeWithNegativeTimezoneOffset(t *testing.T) {
tz := "US/Eastern"
input := time.Date(0, 1, 1, 0, 0, 0, 0, time.FixedZone("", -5))
Expand All @@ -100,7 +113,7 @@ func TestIsValid(t *testing.T) {

for _, tz := range validTZ {
if !IsValid(tz) {
t.Fatalf(`Timezone %q should be valid an it's not`, tz)
t.Fatalf(`Timezone %q should be valid and it's not`, tz)
}
}

Expand All @@ -111,7 +124,7 @@ func TestIsValid(t *testing.T) {

for _, tz := range invalidTZ {
if IsValid(tz) {
t.Fatalf(`Timezone %q should be invalid an it's not`, tz)
t.Fatalf(`Timezone %q should be invalid and it's not`, tz)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions internal/ui/static/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,10 @@ article.category-has-unread {
max-width: 100%;
}

.entry-content iframe {
display: block;
}

.entry-content img {
height: auto;
}
Expand Down
11 changes: 2 additions & 9 deletions internal/validator/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func ValidateUserModification(store *storage.Storage, userID int64, changes *mod
}

if changes.EntryDirection != nil {
if err := validateEntryDirection(*changes.EntryDirection); err != nil {
return err
if err := ValidateDirection(*changes.EntryDirection); err != nil {
return locale.NewLocalizedError("error.invalid_entry_direction")
}
}

Expand Down Expand Up @@ -211,13 +211,6 @@ func validateTimezone(timezoneValue string) *locale.LocalizedError {
return nil
}

func validateEntryDirection(direction string) *locale.LocalizedError {
if direction != "asc" && direction != "desc" {
return locale.NewLocalizedError("error.invalid_entry_direction")
}
return nil
}

func validateEntriesPerPage(entriesPerPage int) *locale.LocalizedError {
if entriesPerPage < 1 {
return locale.NewLocalizedError("error.entries_per_page_invalid")
Expand Down
4 changes: 2 additions & 2 deletions internal/validator/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ func TestValidateTimezone(t *testing.T) {

func TestValidateEntryDirection(t *testing.T) {
for _, direction := range []string{"asc", "desc"} {
if err := validateEntryDirection(direction); err != nil {
if err := ValidateDirection(direction); err != nil {
t.Errorf("expected valid direction %q to pass, got %v", direction, err)
}
}

if err := validateEntryDirection("sideways"); err == nil {
if err := ValidateDirection("sideways"); err == nil {
t.Error("expected invalid direction to fail")
}
}
Expand Down
16 changes: 13 additions & 3 deletions internal/worker/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,41 @@
package worker // import "miniflux.app/v2/internal/worker"

import (
"sync"

"miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/storage"
)

// Pool handles a pool of workers.
// Pool manages a set of background workers that process feed refresh jobs.
type Pool struct {
queue chan model.Job
wg sync.WaitGroup
}

// Push send a list of jobs to the queue.
// Push sends a list of jobs to the queue.
func (p *Pool) Push(jobs model.JobList) {
for _, job := range jobs {
p.queue <- job
}
}

// Shutdown closes the job queue and waits for all workers to finish their current jobs.
func (p *Pool) Shutdown() {
close(p.queue)
p.wg.Wait()
}

// NewPool creates a pool of background workers.
func NewPool(store *storage.Storage, nbWorkers int) *Pool {
workerPool := &Pool{
queue: make(chan model.Job),
}

for i := range nbWorkers {
workerPool.wg.Add(1)
worker := &worker{id: i, store: store}
go worker.Run(workerPool.queue)
go worker.Run(workerPool.queue, &workerPool.wg)
}

return workerPool
Expand Down
11 changes: 6 additions & 5 deletions internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package worker // import "miniflux.app/v2/internal/worker"

import (
"log/slog"
"sync"
"time"

"miniflux.app/v2/internal/config"
Expand All @@ -14,20 +15,20 @@ import (
"miniflux.app/v2/internal/storage"
)

// worker refreshes a feed in the background.
type worker struct {
id int
store *storage.Storage
}

// Run wait for a job and refresh the given feed.
func (w *worker) Run(c <-chan model.Job) {
// Run processes feed refresh jobs from the channel until it is closed.
func (w *worker) Run(c <-chan model.Job, wg *sync.WaitGroup) {
defer wg.Done()

slog.Debug("Worker started",
slog.Int("worker_id", w.id),
)

for {
job := <-c
for job := range c {
slog.Debug("Job received by worker",
slog.Int("worker_id", w.id),
slog.Int64("user_id", job.UserID),
Expand Down
Loading
0