chore: online-config load with standard JSON

- serde-json5 doesn't support UTF-16 surrogate pair properly
  google/serde_json5#21
This commit is contained in:
zonyitoo
2025-11-21 00:00:14 +08:00
parent c53ba5053b
commit afbea321b7
4 changed files with 10 additions and 1 deletions

View File

@@ -196,6 +196,7 @@ smoltcp = { version = "0.12", optional = true, default-features = false, feature
serde = { version = "1.0", features = ["derive"] }
serde_json5 = "0.2"
serde_json = "1.0"
bson = { version = "3.0.0", features = ["serde"], optional = true }
shadowsocks = { version = "1.23.2", path = "../shadowsocks", default-features = false }

View File

@@ -1458,6 +1458,7 @@ macro_rules! impl_from {
impl_from!(::std::io::Error, ErrorKind::IoError, "error while reading file");
impl_from!(serde_json5::Error, ErrorKind::JsonParsingError, "json parse error");
impl_from!(serde_json::Error, ErrorKind::JsonParsingError, "json parse error");
impl Debug for Error {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
@@ -2568,6 +2569,12 @@ impl Config {
Self::load_from_ssconfig(c, config_type)
}
/// Load Config from a JSON `str`
pub fn load_from_json_str(s: &str, config_type: ConfigType) -> Result<Self, Error> {
let c = serde_json::from_str::<SSConfig>(s)?;
Self::load_from_ssconfig(c, config_type)
}
/// Load Config from a File
pub fn load_from_file<P: AsRef<Path>>(filename: P, config_type: ConfigType) -> Result<Self, Error> {
let filename = filename.as_ref();

View File

@@ -190,7 +190,7 @@ impl OnlineConfigService {
Err(..) => return Err(io::Error::other("body contains non-utf8 bytes")),
};
let online_config = match Config::load_from_str(&parsed_body, ConfigType::OnlineConfig) {
let online_config = match Config::load_from_json_str(&parsed_body, ConfigType::OnlineConfig) {
Ok(c) => c,
Err(err) => {
error!(