Merge pull request #99 from hdevalke/master

Do not quote hyphenated strings unnecessarily.
This commit is contained in:
Chen Yuheng 2018-09-04 16:11:11 +08:00 committed by GitHub
commit 5990b5c427
3 changed files with 14 additions and 6 deletions

View file

@ -1,7 +1,7 @@
language: rust language: rust
rust: rust:
- 1.22.1 - 1.22.1
- 1.16.0 - 1.18.0
- beta - beta
- nightly - nightly
matrix: matrix:

View file

@ -1,6 +1,6 @@
install: install:
- ps: Start-FileDownload 'https://static.rust-lang.org/dist/rust-1.16.0-i686-pc-windows-gnu.exe' - ps: Start-FileDownload 'https://static.rust-lang.org/dist/rust-1.18.0-i686-pc-windows-gnu.exe'
- rust-1.16.0-i686-pc-windows-gnu.exe /VERYSILENT /NORESTART /DIR="C:\Program Files (x86)\Rust" - 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:\Program Files (x86)\Rust\bin
- SET PATH=%PATH%;C:\MinGW\bin - SET PATH=%PATH%;C:\MinGW\bin
- rustc -V - rustc -V

View file

@ -281,8 +281,10 @@ impl<'a> YamlEmitter<'a> {
} }
/// Check if the string requires quoting. /// 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. /// 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: /// 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 /// \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 == "" string == ""
|| need_quotes_spaces(string) || need_quotes_spaces(string)
|| string.starts_with(|character: char| {
match character {
':' | '&' | '*' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@' => true,
_ => false,
}
})
|| string.contains(|character: char| { || string.contains(|character: char| {
match character { match character {
':' | '{' | '}' | '[' | ']' | ',' | '&' | '*' | '#' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@' | '`' | '\"' | '\'' | '\\' | '\0' ... '\x06' | '\t' | '\n' | '\r' | '\x0e' ... '\x1a' | '\x1c' ... '\x1f' => true, '{' | '}' | '[' | ']' | ',' | '#' | '`' | '\"' | '\'' | '\\' | '\0' ... '\x06' | '\t' | '\n' | '\r' | '\x0e' ... '\x1a' | '\x1c' ... '\x1f' => true,
_ => false, _ => false,
} }
}) })
@ -402,7 +410,7 @@ products:
a7: a7:
boolean: "true" boolean: "true"
boolean2: "false" boolean2: "false"
date: "2014-12-31" date: 2014-12-31
empty_string: "" empty_string: ""
empty_string1: " " empty_string1: " "
empty_string2: " a" empty_string2: " a"