Skip to content

Commit 5e2410f

Browse files
committed
Fix parsing of no-arg messages
1 parent c2f6dcb commit 5e2410f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

openssl-errors/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ macro_rules! put_error {
217217
$reason,
218218
concat!(file!(), "\0"),
219219
line!(),
220+
// go through format_args to ensure the message string is handled in the same way as the args case
220221
$crate::export::Option::Some($crate::export::Cow::Borrowed(
221-
concat!($message, "\0"),
222+
format_args!(concat!($message, "\0")).as_str().unwrap(),
222223
)),
223224
);
224225
}

openssl-errors/tests/test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn basic() {
2828
error.file().replace(r"\", "/"),
2929
"openssl-errors/tests/test.rs"
3030
);
31-
assert_eq!(error.line(), 20);
31+
assert_eq!(error.line(), line!() - 11);
3232
cfg_if! {
3333
if #[cfg(ossl300)] {
3434
// https://github.com/openssl/openssl/issues/12530
@@ -41,7 +41,7 @@ fn basic() {
4141

4242
#[test]
4343
fn static_data() {
44-
openssl_errors::put_error!(Test::BAR, Test::NO_BACON, "foobar");
44+
openssl_errors::put_error!(Test::BAR, Test::NO_BACON, "foobar {{}}");
4545

4646
let error = Error::get().unwrap();
4747
assert_eq!(error.library().unwrap(), "test library");
@@ -52,8 +52,8 @@ fn static_data() {
5252
error.file().replace(r"\", "/"),
5353
"openssl-errors/tests/test.rs"
5454
);
55-
assert_eq!(error.line(), 44);
56-
assert_eq!(error.data(), Some("foobar"));
55+
assert_eq!(error.line(), line!() - 11);
56+
assert_eq!(error.data(), Some("foobar {}"));
5757
}
5858

5959
#[test]
@@ -69,6 +69,6 @@ fn dynamic_data() {
6969
error.file().replace(r"\", "/"),
7070
"openssl-errors/tests/test.rs"
7171
);
72-
assert_eq!(error.line(), 61);
72+
assert_eq!(error.line(), line!() - 11);
7373
assert_eq!(error.data(), Some("hello world"));
7474
}

0 commit comments

Comments
 (0)