Skip to content

Commit afbea32

Browse files
committed
chore: online-config load with standard JSON
- serde-json5 doesn't support UTF-16 surrogate pair properly google/serde_json5#21
1 parent c53ba50 commit afbea32

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/shadowsocks-service/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ smoltcp = { version = "0.12", optional = true, default-features = false, feature
196196

197197
serde = { version = "1.0", features = ["derive"] }
198198
serde_json5 = "0.2"
199+
serde_json = "1.0"
199200
bson = { version = "3.0.0", features = ["serde"], optional = true }
200201

201202
shadowsocks = { version = "1.23.2", path = "../shadowsocks", default-features = false }

crates/shadowsocks-service/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ macro_rules! impl_from {
14581458

14591459
impl_from!(::std::io::Error, ErrorKind::IoError, "error while reading file");
14601460
impl_from!(serde_json5::Error, ErrorKind::JsonParsingError, "json parse error");
1461+
impl_from!(serde_json::Error, ErrorKind::JsonParsingError, "json parse error");
14611462

14621463
impl Debug for Error {
14631464
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
@@ -2568,6 +2569,12 @@ impl Config {
25682569
Self::load_from_ssconfig(c, config_type)
25692570
}
25702571

2572+
/// Load Config from a JSON `str`
2573+
pub fn load_from_json_str(s: &str, config_type: ConfigType) -> Result<Self, Error> {
2574+
let c = serde_json::from_str::<SSConfig>(s)?;
2575+
Self::load_from_ssconfig(c, config_type)
2576+
}
2577+
25712578
/// Load Config from a File
25722579
pub fn load_from_file<P: AsRef<Path>>(filename: P, config_type: ConfigType) -> Result<Self, Error> {
25732580
let filename = filename.as_ref();

crates/shadowsocks-service/src/local/online_config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl OnlineConfigService {
190190
Err(..) => return Err(io::Error::other("body contains non-utf8 bytes")),
191191
};
192192

193-
let online_config = match Config::load_from_str(&parsed_body, ConfigType::OnlineConfig) {
193+
let online_config = match Config::load_from_json_str(&parsed_body, ConfigType::OnlineConfig) {
194194
Ok(c) => c,
195195
Err(err) => {
196196
error!(

0 commit comments

Comments
 (0)