Roo-Code/src/core
Hannes Rudolph e559beee67
fix: handle YAML parsing edge cases in CustomModesManager (#5099)
* fix: handle YAML parsing edge cases in CustomModesManager

- Add BOM (Byte Order Mark) stripping for UTF-8 and UTF-16
- Normalize invisible characters including non-breaking spaces
- Replace fancy quotes and dashes with standard characters
- Remove zero-width characters that can cause parsing issues
- Add comprehensive test coverage for all edge cases

This fixes the YAML parsing limitations documented in PR #237 by
implementing proper preprocessing before parsing YAML content.

* fix: address PR review comments

- Fix BOM handling to correctly handle UTF-16 (all BOMs appear as \uFEFF when decoded)
- Optimize cleanInvisibleCharacters with single regex pass for better performance
- Prevent duplicate error messages by marking errors as already handled
- Refactor test file to use mockFsReadFile helper function to reduce duplication
- Fix YAML indentation in tests (use spaces instead of tabs)
- Add ESLint disable comment for character class warning (regex is correct)

* fix: prevent YAML line breaks by setting lineWidth to 0

- Added lineWidth: 0 option to all yaml.stringify() calls
- Prevents automatic line wrapping at 80 characters
- Improves readability of YAML output for long strings
- Applied to CustomModesManager, SimpleInstaller, and migrateSettings

* fix: add defaultStringType option to yaml.stringify calls

- Added defaultStringType: 'PLAIN' to minimize formatting changes
- This helps preserve plain scalars when possible
- Works alongside lineWidth: 0 to prevent automatic line wrapping

* refactor: extract problematic characters regex as a named constant

- Move regex pattern to PROBLEMATIC_CHARS_REGEX static constant
- Add comprehensive documentation for each character range
- Improves maintainability and makes the pattern reusable

* test: add comprehensive edge case tests for YAML parsing

- Add test for mixed line endings (CRLF vs LF)
- Add test for multiple BOMs in sequence
- Add test for deeply nested structures with problematic characters
- Ensures robustness across different real-world scenarios

* feat(i18n): add error messages for custom modes in multiple languages

* fix: update tests to expect i18n keys instead of hardcoded strings

- Update CustomModesManager tests to expect translation keys
- Fix YAML edge case tests to match new i18n error messages
- All tests now pass with the i18n integration

* refactor: use strip-bom package and fix error handling

- Replace custom stripBOM method with existing strip-bom package
- Fix duplicate error handling in parseYamlSafely by returning empty object instead of re-throwing
- Addresses review comments from PR #5099

---------

Co-authored-by: Daniel Riccio <ricciodaniel98@gmail.com>
2025-06-25 20:22:21 -04:00
..
assistant-message Fix: Allow write_to_file to handle newline-only and empty content (#3550) 2025-06-23 18:43:49 -04:00
checkpoints Disable checkpoint if nested git repos are detected (#4509) 2025-06-10 13:29:19 -07:00
condense feat: add profile-specific context condensing thresholds (#4456) 2025-06-20 23:02:04 -04:00
config fix: handle YAML parsing edge cases in CustomModesManager (#5099) 2025-06-25 20:22:21 -04:00
context-tracking fix: use safeWriteJson for all JSON file writes with race condition fix (#4733) 2025-06-25 16:05:02 -04:00
diff fix: start line not working in multiple apply diff (#5019) 2025-06-22 23:33:52 -04:00
environment Include the cwd in the terminal details (#4783) 2025-06-17 11:53:49 -04:00
ignore Farewell jest (#4607) 2025-06-16 21:39:45 -07:00
mentions Farewell jest (#4607) 2025-06-16 21:39:45 -07:00
prompts feat: add support for loading rules from global and project-local .roo directories (#5016) 2025-06-24 11:40:45 -04:00
protect Add logic to prevent auto-approving edits of configuration files (#4667) 2025-06-13 19:58:55 -04:00
sliding-window feat: add profile-specific context condensing thresholds (#4456) 2025-06-20 23:02:04 -04:00
task feat: add profile-specific context condensing thresholds (#4456) 2025-06-20 23:02:04 -04:00
task-persistence fix: use safeWriteJson for all JSON file writes with race condition fix (#4733) 2025-06-25 16:05:02 -04:00
tools Fix: Allow write_to_file to handle newline-only and empty content (#3550) 2025-06-23 18:43:49 -04:00
webview Git repo cloud telemetry (#5119) 2025-06-25 17:01:32 -07:00