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

Fix infinite recursion in Preprocessor when book.toml is next to book destination #116

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

srehm
Copy link
Contributor

@srehm srehm commented Sep 28, 2024

I have a book layout that looks as:

  • book.toml
  • foo.md
  • bar/bar.md

That results in an infinite recursion while copying the files to the "book/pdf" destination directory as that directory repeatedly get copied into itself.

The attached patch fixes this by checking if the file to be copied is within the destination directory and skipping it accordingly.

Copy link
Owner

@max-heller max-heller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! This looks good, just one clippy fix:

error: the borrowed expression implements the required traits
   --> src/preprocess.rs:108:32
    |
108 |             if src.starts_with(&ctx.book.destination.as_path()) {
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `ctx.book.destination.as_path()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
    = note: `-D clippy::needless-borrows-for-generic-args` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::needless_borrows_for_generic_args)]`

@srehm srehm requested a review from max-heller October 1, 2024 18:55
@max-heller max-heller merged commit 247cfb7 into max-heller:main Oct 1, 2024
13 checks passed
@max-heller max-heller mentioned this pull request Oct 1, 2024
max-heller added a commit that referenced this pull request Oct 3, 2024
## 🤖 New release
* `mdbook-pandoc`: 0.7.2 -> 0.7.3

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.7.3] - 2024-10-01

### Bug Fixes

- Prevent infinite recursion when source directory contains destination
directory ([#116](#116))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants