Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow special characters in directory name, optimization #68

Merged
merged 4 commits into from
Aug 18, 2023
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
5 changes: 3 additions & 2 deletions htmlproofer/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def on_post_build(self, config: Config) -> None:
if self.config['raise_error_after_finish'] and self.invalid_links:
raise PluginError("Invalid links present.")

def on_page_markdown(self, markdown: str, page: Page, config: Config, files: Files) -> None:
def on_files(self, files: Files, config: Config) -> None:
# Store files to allow inspecting Markdown files in later stages.
self.files.update({os.path.normpath(file.url): file for file in files})

Expand Down Expand Up @@ -223,7 +223,8 @@ def find_source_file(url: str, src_path: str, files: Dict[str, File]) -> Optiona
search_path = os.path.normpath(url[1:])
else:
# Handle relative links by concatenating the source dir with the destination path
search_path = os.path.normpath(str(pathlib.Path(src_path).parent / pathlib.Path(url)))
src_dir = urllib.parse.quote(str(pathlib.Path(src_path).parent), safe='/\\')
search_path = os.path.normpath(str(pathlib.Path(src_dir) / pathlib.Path(url)))

try:
return files[search_path]
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,12 @@ def test_get_external_url__unknown_scheme(scheme):
def test_get_url_status__local_page(plugin):
index_page = Mock(spec=Page, markdown='# Heading\nContent')
page1_page = Mock(spec=Page, markdown='# Page One\n## Sub Heading\nContent')
special_char_page = Mock(spec=Page, markdown='# Heading éèà\n## Sub Heading éèà\nContent')
files = {os.path.normpath(file.url): file for file in Files([
Mock(spec=File, src_path='index.md', dest_path='index.html', url='index.html', page=index_page),
Mock(spec=File, src_path='page1.md', dest_path='page1.html', url='page1.html', page=page1_page),
Mock(spec=File, src_path='Dir éèà/éèà.md', dest_path='Dir éèà/éèà.html',
url='Dir%20%C3%A9%C3%A8%C3%A0/%C3%A9%C3%A8%C3%A0.html', page=special_char_page),
])}

assert plugin.get_url_status('index.html', 'page1.md', set(), files, False) == 0
Expand All @@ -256,6 +259,10 @@ def test_get_url_status__local_page(plugin):
assert plugin.get_url_status('page2.html', 'page1.md', set(), files, False) == 404
assert plugin.get_url_status('page2.html#heading', 'page1.md', set(), files, False) == 404

assert plugin.get_url_status('Dir%20%C3%A9%C3%A8%C3%A0/%C3%A9%C3%A8%C3%A0.html#sub-heading-eea',
'page1.md', set(), files, False) == 0
assert plugin.get_url_status('%C3%A9%C3%A8%C3%A0.html#sub-heading-eea', 'Dir éèà/page3.md', set(), files, False) == 0


def test_get_url_status__non_markdown_page(plugin):
index_page = Mock(spec=Page, markdown='# Heading\nContent')
Expand Down