-
Notifications
You must be signed in to change notification settings - Fork 103
support JSONC comments in config profile validation
#154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { createPublicKey, createPrivateKey, KeyObject } from 'node:crypto'; | ||
| import { hasher } from 'node-object-hash'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import { parse } from 'jsonc-parser'; | ||
|
|
||
| import { HashedSet } from '@remnawave/hashed-set'; | ||
|
|
||
|
|
@@ -61,9 +62,9 @@ export class XRayConfig { | |
|
|
||
| if (typeof configInput === 'string') { | ||
| try { | ||
| config = JSON.parse(configInput) as IXrayConfig; | ||
| config = parse(configInput) as IXrayConfig; | ||
| } catch (error) { | ||
| throw new Error(`Invalid JSON input or file path: ${error}`); | ||
| throw new Error(`Invalid JSON/JSONC input: ${error}`); | ||
| } | ||
|
Comment on lines
64
to
68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
According to the official
The fix is to pass an import { parse, ParseError } from 'jsonc-parser';
if (typeof configInput === 'string') {
const errors: ParseError[] = [];
config = parse(configInput, errors) as IXrayConfig;
if (errors.length > 0) {
throw new Error(`Invalid JSON/JSONC input: error code ${errors[0].error} at offset ${errors[0].offset}`);
}
} |
||
| } else if (typeof configInput === 'object') { | ||
| config = configInput as IXrayConfig; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stringThe Zod schema now infers
configasstring | Record<string, unknown>, butConfigProfileService.createConfigProfilestill declaresconfig: object:In TypeScript,
stringis not assignable toobject, so passingcreateConfigProfileDto.config(which isstring | Record<string, unknown>) to this method is a type error that will break compilation.The service (and likewise
updateConfigProfile) needs its signature updated:The same applies to
src/modules/config-profiles/config-profile.service.tsline 133 (createConfigProfile) and line 192 (updateConfigProfile).