fix: standardize version parsing and simplify string escaping
This commit is contained in:
1 parent
4e2b6b1200
commit
38a7c3da63
23 files changed
+245
-137
No files matched your search
@@ -1,11 +1,11 @@
|
||||
import type { AnyMessageSegment } from '../types/index';
|
||||
|
||||
export function escapeCqText(text: string): string {
|
||||
return text.replace(/&/g, '&').replace(/\[/g, '[').replace(/\]/g, ']');
|
||||
return text.replaceAll('&', '&').replaceAll('[', '[').replaceAll(']', ']');
|
||||
}
|
||||
|
||||
export function escapeCqParam(text: string): string {
|
||||
return escapeCqText(text).replace(/,/g, ',');
|
||||
return escapeCqText(text).replaceAll(',', ',');
|
||||
}
|
||||
|
||||
export function segmentsToCQString(segments: AnyMessageSegment[]): string {
|
||||
|
||||
@@ -59,12 +59,12 @@ function parseCQParams(raw: string): Record<string, string> {
|
||||
}
|
||||
|
||||
function cqUnescape(text: string): string {
|
||||
return text.replace(/[/g, '[').replace(/]/g, ']').replace(/&/g, '&');
|
||||
return text.replaceAll('[', '[').replaceAll(']', ']').replaceAll('&', '&');
|
||||
}
|
||||
|
||||
function cqUnescapeParam(text: string): string {
|
||||
// Decode ampersands last so literal entity text is not decoded twice.
|
||||
return cqUnescape(text.replace(/,/g, ','));
|
||||
return cqUnescape(text.replaceAll(',', ','));
|
||||
}
|
||||
|
||||
function segmentFromCq(type: string, data: Record<string, string>): AnyMessageSegment {
|
||||
|
||||
Reference in new issue
Block a user