SmartJoin incorrectly treats relative paths containing special variable names as special paths - #3022
Conversation
|
Um, AI wrote the code, correct? |
|
Yes, Codex helped with part of the implementation and tests. I worked through the issue and the scope of the fix myself, and went over the implementation a few times before opening the PR. I also changed some parts manually after reviewing the generated code. I'm familiar with the behavior this is trying to preserve — in particular, I ran the tests and lint locally and checked the regression cases before submitting. Happy to explain any part of the change or adjust it based on feedback. |
|
Why wouldn't you just do this? |
|
Yeah, I considered that option too. My main concern was that matching only the exact strings might stop some template forms that currently work, for example That's why I went with matching inside template actions instead. It avoids treating literal paths like That said, if only the canonical |
|
Yes, I wondered the same thing, would it matter? Lets assume it would cause problems, then my approach would be to use a regular expression for each item in knownAbsDirs (rather than the string), and precompile those (so package level vars, precompile for performance) and finally apply the regex list in a tight loop (similar to existing code). It would be easier to understand. Or a single regex that considers all 3 possibilities. Probably faster again. |
|
Yeah, that makes sense. A precompiled regex should make this a bit clearer without losing the template variants I was worried about. I'll update Thanks for the suggestion! |
|
@znnnnnnn-wil Looks quite good. You will need to request a review from one of the maintainers (I would suggest @vmaerten). |
|
@vmaerten, when you have a chance, could you take a look at this PR? trulede suggested requesting your review. Thanks! |
Fixes #3021
Description
SmartJoinincorrectly treats ordinary relative paths containing special variable names such as.ROOT_DIRas absolute/special paths, causing them to bypass the base-directory join.The path should be treated as a normal relative path and joined with
base.From looking at the implementation, this may be caused by
isSpecialDirusingstrings.Containsto detect special variables. As a result, an ordinary directory name containing one of these strings can be matched even when the variable is not actually part of a{{ ... }}template expression.A small portion of the code and tests was generated with assistance from Codex.
Checklist