From 2ad74a791b3b3b3abad90cbb4096d80c076dc538 Mon Sep 17 00:00:00 2001 From: Hannes De Valkeneer Date: Fri, 20 Apr 2018 08:06:55 +0200 Subject: [PATCH 1/2] Do not quote hyphenated strings unnecessarily. fixes #54 --- saphyr/src/emitter.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/saphyr/src/emitter.rs b/saphyr/src/emitter.rs index c77263c..68fe8a4 100644 --- a/saphyr/src/emitter.rs +++ b/saphyr/src/emitter.rs @@ -281,8 +281,10 @@ impl<'a> YamlEmitter<'a> { } /// Check if the string requires quoting. +/// Strings starting with any of the following characters must be quoted. +/// :, &, *, ?, |, -, <, >, =, !, %, @ /// Strings containing any of the following characters must be quoted. -/// :, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, ` +/// {, }, [, ], ,, #, ` /// /// If the string contains any of the following control characters, it must be escaped with double quotes: /// \0, \x01, \x02, \x03, \x04, \x05, \x06, \a, \b, \t, \n, \v, \f, \r, \x0e, \x0f, \x10, \x11, \x12, \x13, \x14, \x15, \x16, \x17, \x18, \x19, \x1a, \e, \x1c, \x1d, \x1e, \x1f, \N, \_, \L, \P @@ -300,9 +302,15 @@ fn need_quotes(string: &str) -> bool { string == "" || need_quotes_spaces(string) + || string.starts_with(|character: char| { + match character { + ':' | '&' | '*' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@' => true, + _ => false, + } + }) || string.contains(|character: char| { match character { - ':' | '{' | '}' | '[' | ']' | ',' | '&' | '*' | '#' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@' | '`' | '\"' | '\'' | '\\' | '\0' ... '\x06' | '\t' | '\n' | '\r' | '\x0e' ... '\x1a' | '\x1c' ... '\x1f' => true, + '{' | '}' | '[' | ']' | ',' | '#' | '`' | '\"' | '\'' | '\\' | '\0' ... '\x06' | '\t' | '\n' | '\r' | '\x0e' ... '\x1a' | '\x1c' ... '\x1f' => true, _ => false, } }) @@ -402,7 +410,7 @@ products: a7: 你好 boolean: "true" boolean2: "false" -date: "2014-12-31" +date: 2014-12-31 empty_string: "" empty_string1: " " empty_string2: " a" From 82377440914dbde55c527275bd8bb0a764eecb03 Mon Sep 17 00:00:00 2001 From: Hannes De Valkeneer Date: Fri, 20 Apr 2018 21:29:50 +0200 Subject: [PATCH 2/2] update minimum version to 1.18.0 because of env_logger --- saphyr/.travis.yml | 2 +- saphyr/appveyor.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/saphyr/.travis.yml b/saphyr/.travis.yml index 1a2be7b..75f44f7 100644 --- a/saphyr/.travis.yml +++ b/saphyr/.travis.yml @@ -1,7 +1,7 @@ language: rust rust: - 1.22.1 - - 1.16.0 + - 1.18.0 - beta - nightly matrix: diff --git a/saphyr/appveyor.yml b/saphyr/appveyor.yml index 5ee211c..240c3d9 100644 --- a/saphyr/appveyor.yml +++ b/saphyr/appveyor.yml @@ -1,6 +1,6 @@ install: - - ps: Start-FileDownload 'https://static.rust-lang.org/dist/rust-1.16.0-i686-pc-windows-gnu.exe' - - rust-1.16.0-i686-pc-windows-gnu.exe /VERYSILENT /NORESTART /DIR="C:\Program Files (x86)\Rust" + - ps: Start-FileDownload 'https://static.rust-lang.org/dist/rust-1.18.0-i686-pc-windows-gnu.exe' + - rust-1.18.0-i686-pc-windows-gnu.exe /VERYSILENT /NORESTART /DIR="C:\Program Files (x86)\Rust" - SET PATH=%PATH%;C:\Program Files (x86)\Rust\bin - SET PATH=%PATH%;C:\MinGW\bin - rustc -V