Skip to content
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

Reject suffixed string literals inside serde attrs #2499

Merged
merged 2 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion serde_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = "2.0.24"
syn = "2.0.25"

[dev-dependencies]
serde = { version = "1.0", path = "../serde" }
Expand Down
7 changes: 7 additions & 0 deletions serde_derive/src/internals/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,13 @@ fn get_lit_str2(
..
}) = value
{
let suffix = lit.suffix();
if !suffix.is_empty() {
cx.error_spanned_by(
lit,
format!("unexpected suffix `{}` on string literal", suffix),
);
}
Ok(Some(lit.clone()))
} else {
cx.error_spanned_by(
Expand Down
2 changes: 1 addition & 1 deletion serde_derive_internals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ path = "lib.rs"
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "2.0.24", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
syn = { version = "2.0.25", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
10 changes: 10 additions & 0 deletions test_suite/tests/ui/malformed/str_suffix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde::Serialize;

#[derive(Serialize)]
#[serde(bound = ""huh)]
pub struct Struct {
#[serde(rename = ""what)]
pub field: i32,
}

fn main() {}
11 changes: 11 additions & 0 deletions test_suite/tests/ui/malformed/str_suffix.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: unexpected suffix `huh` on string literal
--> tests/ui/malformed/str_suffix.rs:4:17
|
4 | #[serde(bound = ""huh)]
| ^^^^^

error: unexpected suffix `what` on string literal
--> tests/ui/malformed/str_suffix.rs:6:22
|
6 | #[serde(rename = ""what)]
| ^^^^^^