-
Notifications
You must be signed in to change notification settings - Fork 726
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement base element handling in content scraper
- Loading branch information
Showing
5 changed files
with
223 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package readability // import "miniflux.app/v2/internal/reader/readability" | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestBaseURL(t *testing.T) { | ||
html := ` | ||
<html> | ||
<head> | ||
<base href="https://example.org/ "> | ||
</head> | ||
<body> | ||
<article> | ||
Some content | ||
</article> | ||
</body> | ||
</html>` | ||
|
||
baseURL, _, err := ExtractContent(strings.NewReader(html)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if baseURL != "https://example.org/" { | ||
t.Errorf(`Unexpected base URL, got %q instead of "https://example.org/"`, baseURL) | ||
} | ||
} | ||
|
||
func TestMultipleBaseURL(t *testing.T) { | ||
html := ` | ||
<html> | ||
<head> | ||
<base href="https://example.org/ "> | ||
<base href="https://example.com/ "> | ||
</head> | ||
<body> | ||
<article> | ||
Some content | ||
</article> | ||
</body> | ||
</html>` | ||
|
||
baseURL, _, err := ExtractContent(strings.NewReader(html)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if baseURL != "https://example.org/" { | ||
t.Errorf(`Unexpected base URL, got %q instead of "https://example.org/"`, baseURL) | ||
} | ||
} | ||
|
||
func TestRelativeBaseURL(t *testing.T) { | ||
html := ` | ||
<html> | ||
<head> | ||
<base href="/test/ "> | ||
</head> | ||
<body> | ||
<article> | ||
Some content | ||
</article> | ||
</body> | ||
</html>` | ||
|
||
baseURL, _, err := ExtractContent(strings.NewReader(html)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if baseURL != "" { | ||
t.Errorf(`Unexpected base URL, got %q`, baseURL) | ||
} | ||
} | ||
|
||
func TestWithoutBaseURL(t *testing.T) { | ||
html := ` | ||
<html> | ||
<head> | ||
<title>Test</title> | ||
</head> | ||
<body> | ||
<article> | ||
Some content | ||
</article> | ||
</body> | ||
</html>` | ||
|
||
baseURL, _, err := ExtractContent(strings.NewReader(html)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if baseURL != "" { | ||
t.Errorf(`Unexpected base URL, got %q instead of ""`, baseURL) | ||
} | ||
} |
This file contains 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
Oops, something went wrong.