Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Privacy plugin breaks on files stored in memory #7803

Closed
4 tasks done
landmaj opened this issue Dec 16, 2024 · 2 comments
Closed
4 tasks done

Privacy plugin breaks on files stored in memory #7803

landmaj opened this issue Dec 16, 2024 · 2 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@landmaj
Copy link

landmaj commented Dec 16, 2024

Context

The bug was encountered by a user of mkdocs-d2-plugin. Relevant issue: landmaj/mkdocs-d2-plugin#21

Bug description

The privacy plugin passes abs_src_path to open() without checking for None, which results in an error:

TypeError: expected str, bytes or os.PathLike object, not NoneType

None is a valid value since MkDocs 1.6, as described here:

Since MkDocs 1.6 a file may alternatively be stored in memory - content_string/content_bytes.

Then src_dir and abs_src_path will remain None. content_bytes/content_string need to be written to, or populated through the content argument in the constructor.

The (valid) code in my plugin which causes privacy plugin to crash is this:

  def on_files(self, files: Files, config):
      content = importlib_files("d2.css").joinpath("mkdocs_d2_plugin.css").read_text()
      file = File(
          "assets/stylesheets/mkdocs_d2_plugin.css",
          None,
          config["site_dir"],
          config["use_directory_urls"],
      )
      file.content_string = content

      files.append(file)

Related links

Reproduction

9.5.48-privacy-plugin-crash.zip

Steps to reproduce

  1. Run mkdocs build with privacy and d2 plugins enabled.

Browser

No response

Before submitting

@squidfunk
Copy link
Owner

squidfunk commented Dec 16, 2024

Thanks for reporting. Fixed in 968fbe1. To be honest, a fundamental change like this to MkDocs' plugin API would actually mandate a major release, IMHO. We're probably not the only plugin that is impacted by this breaking change.

@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open labels Dec 16, 2024
@squidfunk
Copy link
Owner

Released as part of 9.5.49.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants