Commit e559bee
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 <[email protected]>1 parent 896e986 commit e559bee
File tree
23 files changed
+806
-26
lines changed- src
- core/config
- __tests__
- i18n/locales
- ca
- de
- en
- es
- fr
- hi
- id
- it
- ja
- ko
- nl
- pl
- pt-BR
- ru
- tr
- vi
- zh-CN
- zh-TW
- services/marketplace
- utils
23 files changed
+806
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
76 | 142 | | |
77 | 143 | | |
78 | 144 | | |
79 | | - | |
| 145 | + | |
80 | 146 | | |
| 147 | + | |
81 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
82 | 160 | | |
83 | 161 | | |
84 | 162 | | |
| |||
89 | 167 | | |
90 | 168 | | |
91 | 169 | | |
92 | | - | |
93 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
94 | 175 | | |
95 | 176 | | |
96 | 177 | | |
| |||
124 | 205 | | |
125 | 206 | | |
126 | 207 | | |
127 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
128 | 214 | | |
129 | 215 | | |
130 | 216 | | |
| |||
147 | 233 | | |
148 | 234 | | |
149 | 235 | | |
150 | | - | |
151 | | - | |
| 236 | + | |
152 | 237 | | |
153 | 238 | | |
154 | 239 | | |
155 | 240 | | |
156 | | - | |
| 241 | + | |
157 | 242 | | |
158 | 243 | | |
159 | 244 | | |
| |||
284 | 369 | | |
285 | 370 | | |
286 | 371 | | |
287 | | - | |
| 372 | + | |
288 | 373 | | |
289 | 374 | | |
290 | 375 | | |
| |||
318 | 403 | | |
319 | 404 | | |
320 | 405 | | |
321 | | - | |
| 406 | + | |
322 | 407 | | |
323 | 408 | | |
324 | 409 | | |
| |||
329 | 414 | | |
330 | 415 | | |
331 | 416 | | |
332 | | - | |
| 417 | + | |
333 | 418 | | |
334 | 419 | | |
335 | 420 | | |
336 | 421 | | |
337 | 422 | | |
338 | | - | |
| 423 | + | |
339 | 424 | | |
340 | | - | |
| 425 | + | |
341 | 426 | | |
342 | 427 | | |
343 | 428 | | |
344 | 429 | | |
345 | | - | |
| 430 | + | |
346 | 431 | | |
347 | 432 | | |
348 | 433 | | |
| |||
373 | 458 | | |
374 | 459 | | |
375 | 460 | | |
376 | | - | |
| 461 | + | |
377 | 462 | | |
378 | 463 | | |
379 | 464 | | |
| |||
392 | 477 | | |
393 | 478 | | |
394 | 479 | | |
395 | | - | |
396 | | - | |
397 | | - | |
| 480 | + | |
| 481 | + | |
398 | 482 | | |
399 | 483 | | |
400 | 484 | | |
401 | 485 | | |
402 | 486 | | |
403 | 487 | | |
404 | | - | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
405 | 492 | | |
406 | 493 | | |
407 | 494 | | |
408 | 495 | | |
409 | | - | |
410 | | - | |
411 | | - | |
| 496 | + | |
| 497 | + | |
412 | 498 | | |
413 | 499 | | |
414 | 500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
754 | 754 | | |
755 | 755 | | |
756 | 756 | | |
757 | | - | |
| 757 | + | |
758 | 758 | | |
759 | 759 | | |
760 | 760 | | |
| |||
0 commit comments