Skip to content

Commit

Permalink
Sanitize % in r_print!() (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
yutannihilation authored May 17, 2024
1 parent 2458189 commit 7bfdb36
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#> [1] -1
```

### Bug fixes

* `r_print!()` and `r_eprint!()` now can print strings containing `%`.

## [v0.6.3] (2024-05-05)

### New features
Expand Down
4 changes: 2 additions & 2 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) const LINEBREAK: [c_char; 2] = [b'\n' as _, b'\0' as _];
pub fn r_print(msg: &str, linebreak: bool) {
if !msg.is_empty() {
// ignore error
let _ = r_stdout().write_all(msg.as_bytes());
let _ = r_stdout().write_all(msg.replace('%', "%%").as_bytes());
}

unsafe {
Expand All @@ -20,7 +20,7 @@ pub fn r_print(msg: &str, linebreak: bool) {
pub fn r_eprint(msg: &str, linebreak: bool) {
if !msg.is_empty() {
// ignore error
let _ = r_stderr().write_all(msg.as_bytes());
let _ = r_stderr().write_all(msg.replace('%', "%%").as_bytes());
}

unsafe {
Expand Down

0 comments on commit 7bfdb36

Please sign in to comment.