-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2493 from jarhodes314/bug/smartrest-errors-quotes
Support quotes in Cumulocity failureReason field
- Loading branch information
Showing
30 changed files
with
594 additions
and
624 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pub fn fields_to_csv_string(record: &[&str]) -> String { | ||
let mut writer = csv::Writer::from_writer(vec![]); | ||
writer | ||
.write_record(record) | ||
.expect("write to vec never fails"); | ||
let mut output = writer.into_inner().expect("write to vec never fails"); | ||
output.pop(); | ||
String::from_utf8(output).expect("all input is utf-8") | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::smartrest::csv::fields_to_csv_string; | ||
|
||
#[test] | ||
fn normal_fields_containing_commas_are_quoted() { | ||
assert_eq!(fields_to_csv_string(&["503", "test,me"]), "503,\"test,me\""); | ||
} | ||
|
||
#[test] | ||
fn normal_fields_containing_quotes_are_quoted() { | ||
let rcd = fields_to_csv_string(&["503", r#"A value"with" quotes"#, "field"]); | ||
assert_eq!(rcd, r#"503,"A value""with"" quotes",field"#); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod alarm; | ||
pub mod csv; | ||
pub mod error; | ||
pub mod inventory; | ||
pub mod message; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
1ef77c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Robot Results