fop(1): fixes glaring issue with newline handling

This commit is contained in:
Emma Tebibyte 2024-07-28 01:15:08 -06:00
parent 0f121cbac7
commit d2ae35eac9
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270

View File

@ -71,7 +71,7 @@ fn main() {
let mut buf = String::new();
if let Err(e) = stdin().read_to_string(&mut buf) {
eprintln!("{}: {}", argv[0], e.strerror);
eprintln!("{}: {}", argv[0], e.strerror());
exit(EX_IOERR);
};
@ -120,8 +120,13 @@ fn main() {
/* get the output with which the original field will be replaced */
let mut replace = output.stdout.clone();
/* as long as its not a newline, set the replacement to the output */
if replace.pop() != Some(b'\n') { replace = output.stdout; }
/* pop trailing newline out if the input did not contain it */
if fields[index].chars().last() != Some('\n') /* no newline */
&& replace.pop() != Some(b'\n') { /* pop last char of replacement */
/* restore replacement to original command output if popped char was not
* a newline */
replace = output.stdout;
}
/* convert the output of the program to UTF-8 */
let new_field = String::from_utf8(replace).unwrap_or_else(|e| {