Fix command argument parsing bug when token substring matches earlier token#626
Merged
Bishbash777 merged 6 commits intoTorchAPI:masterfrom Jan 28, 2026
Merged
Fix command argument parsing bug when token substring matches earlier token#626Bishbash777 merged 6 commits intoTorchAPI:masterfrom
Bishbash777 merged 6 commits intoTorchAPI:masterfrom
Conversation
… token
## Fix command argument parsing bug when token substring matches earlier token
### Changes
- **Bug Fix**: Revised `CommandTree.GetCommand` method to correctly extract arguments from command strings.
- **Minor Formatting**: Updated array initializer syntax for consistency.
### Bug Description
The previous implementation used `IndexOf(split[skip])` to locate the start of the arguments within the original command text. This approach fails when an earlier command token contains the argument token as a substring. For example, given the command `"qs storegrid ore 10000"`, the token `"ore"` appears inside the preceding token `"storegrid"`. `IndexOf` would then return the position inside `"storegrid"`, causing `argText` to incorrectly start at `"oregrid ore 10000"` rather than at the actual argument `"ore 10000"`.
### Solution
The fix tracks the position of each preceding token by iterating over the command tokens up to the argument start. For each token, we locate it in the original string using a case‑sensitive ordinal search, advance the position past the token and any trailing spaces, and finally take the substring from that position. This ensures the argument text begins exactly after the full command name.
### Code Changes
1. **Line 99**: Changed `new []{' '}` to `new[] { ' ' }` (cosmetic).
2. **Lines 106–145**: Replaced the faulty substring logic with a robust token‑position tracking algorithm. Added detailed inline comments explaining the bug and the fix.
3. **Line 147**: Added a blank line for readability.
### Impact
- Commands with overlapping token substrings will now parse arguments correctly.
- No breaking changes; the method signature and overall behavior remain unchanged.
- Improves reliability of command‑line parsing in Torch's command system.
…ry structure Move dedicated server files to 'game' subdirectory Add retry logic and error handling for SteamCMD updates Remove unused using statements Centralize path calculation with GetDedicatedServer64Path method
…evelopers - Added EnsureDedicatedServer64Symlink method that creates a directory junction from ./DedicatedServer64 to ./game/DedicatedServer64 for backward compatibility with plugin development workflows.
- Ensure world list refreshes after new world creation by calling RefreshModel in InstanceManager.SelectWorld
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.
Fix command argument parsing bug when token substring matches earlier token
Changes
CommandTree.GetCommandmethod to correctly extract arguments from command strings.Bug Description
The previous implementation used
IndexOf(split[skip])to locate the start of the arguments within the original command text. This approach fails when an earlier command token contains the argument token as a substring. For example, given the command"qs storegrid ore 10000", the token"ore"appears inside the preceding token"storegrid".IndexOfwould then return the position inside"storegrid", causingargTextto incorrectly start at"oregrid ore 10000"rather than at the actual argument"ore 10000".Solution
The fix tracks the position of each preceding token by iterating over the command tokens up to the argument start. For each token, we locate it in the original string using a case‑sensitive ordinal search, advance the position past the token and any trailing spaces, and finally take the substring from that position. This ensures the argument text begins exactly after the full command name.
Code Changes
new []{' '}tonew[] { ' ' }(cosmetic).Impact