fix: properly expand tilde (~) in path configuration options#81
Open
yuyuan12138 wants to merge 1 commit intoxeluxee:masterfrom
Open
fix: properly expand tilde (~) in path configuration options#81yuyuan12138 wants to merge 1 commit intoxeluxee:masterfrom
yuyuan12138 wants to merge 1 commit intoxeluxee:masterfrom
Conversation
Fix path resolution for configuration options that accept file paths. Previously, paths starting with ~ were treated as relative paths and literal directory names (e.g., ~/cp/testcases created a directory named "~" in the current working directory). Changes: - Add normalize_path() to expand ~ to home directory and normalize paths - Add resolve_config_path() for smart absolute/relative path resolution - Normalize path options during configuration loading - Update all path-related configuration usage: - testcases_directory - compile_directory - running_directory - received_problems_path - received_contests_directory - received_contests_problems_path - template_file Backward compatibility maintained: - Relative paths (., ./path, ../path) still work as before - $(HOME) modifier in file format strings continues to work - Absolute paths work correctly Fixes xeluxee#78 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title
fix: properly expand tilde (~) in path configuration options
Description
This PR fixes the path resolution bug reported in #78, where configuration options that accept file paths would not properly expand the tilde (~) to the user's home directory.
Problem
Previously, when users configured paths like:
testcases_directory = "~/cp/testcases"
The plugin would incorrectly treat this as a relative path, creating a directory literally named ~/cp/testcases in the current working directory, instead of resolving it to
/home/user/cp/testcases.
Solution
This fix introduces proper path expansion and normalization:
- normalize_path() - Expands ~ to home directory and converts to absolute path
- resolve_config_path() - Smart resolution that distinguishes between absolute paths (starting with ~ or /) and relative paths
- Added normalize_path_config() in config.lua to normalize path options when configuration is loaded
- Applied to both global setup and local .competitest.lua configurations
- testcases_directory
- compile_directory
- running_directory
- received_problems_path
- received_contests_directory
- received_contests_problems_path
- template_file
Backward Compatibility
✅ Fully backward compatible - all existing configurations continue to work:
Example Usage
After this fix, all of these configurations work correctly:
require('competitest').setup({
-- Tilde expansion (newly fixed)
testcases_directory = "~/cp/testcases",
})
Changes
Total: 5 files changed, 85 insertions(+), 4 deletions(-)
Testing
Thoroughly tested with:
Fixes #78