forked from lobehub/lobe-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 fix: Extra Backslash in Code Blocks ($0 -> /$0) (lobehub#177)
* Update utils.ts * fix: Update escapeDollarNumber function to handle code blocks and single line code blocks * Create utils.test.ts * Update utils.test.ts
- Loading branch information
Showing
2 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { escapeDollarNumber } from './utils'; | ||
|
||
describe('escapeDollarNumber', () => { | ||
it('should escape dollar signs followed by numbers', () => { | ||
expect(escapeDollarNumber('This costs $10.')).toBe('This costs \\$10.'); | ||
expect(escapeDollarNumber('I have $20 and you have $30')).toBe('I have \\$20 and you have \\$30'); | ||
}); | ||
|
||
it('should not escape dollar signs in code blocks', () => { | ||
expect(escapeDollarNumber('```\n$10\n```')).toBe('```\n$10\n```'); | ||
expect(escapeDollarNumber('This is a inline code block: `$10`')).toBe('This is a inline code block: `$10`'); | ||
}); | ||
|
||
it('should handle multiple cases', () => { | ||
expect(escapeDollarNumber('This costs $10. But this code is fine: `$10`.')).toBe('This costs \\$10. But this code is fine: `$10`.'); | ||
}); | ||
|
||
it('should handle edge cases', () => { | ||
expect(escapeDollarNumber('')).toBe(''); | ||
expect(escapeDollarNumber('$')).toBe('$'); | ||
expect(escapeDollarNumber('$$')).toBe('$$'); | ||
expect(escapeDollarNumber('$1$2$3')).toBe('\\$1\\$2\\$3'); // 多个需要转义的情况 | ||
}); | ||
}); |
This file contains 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