Skip to content

Commit

Permalink
Escape \ in strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
dragos authored and jayv committed Mar 30, 2016
1 parent 8dc77f4 commit 82cd03d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private[spark] class MesosClusterScheduler(
val ShellSpecialChars = (""".*([ '<>&|\?\*;!#\\(\)"$`]).*""").r
value match {
case WrappedInQuotes(c) => value // The user quoted his args, don't touch it!
case ShellSpecialChars(c) => "\"" + value.replaceAll("""(["`\$])""", """\\$1""") + "\""
case ShellSpecialChars(c) => "\"" + value.replaceAll("""(["`\$\\])""", """\\$1""") + "\""
case _: String => value // Don't touch harmless strings
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,13 @@ class MesosClusterSchedulerSuite extends SparkFunSuite with LocalSparkContext wi
assert(escape("shouldescape\"quote") === wrapped("shouldescape\\\"quote"))
assert(escape("should escape this $ dollar") === wrapped("should escape this \\$ dollar"))
assert(escape("should escape this ` backtick") === wrapped("should escape this \\` backtick"))
assert(escape("""should escape this \ backslash""")
=== wrapped("""should escape this \\ backslash"""))
assert(escape("""\"?""") === wrapped("""\\\"?"""))


// Special Chars no escape only wrap
List(" ", "'", "<", ">", "&", "|", "?", "*", ";", "!", "#", "\\", "(", ")").foreach(char => {
List(" ", "'", "<", ">", "&", "|", "?", "*", ";", "!", "#", "(", ")").foreach(char => {
assert(escape(s"onlywrap${char}this") === wrapped(s"onlywrap${char}this"))
})
}
Expand Down

0 comments on commit 82cd03d

Please sign in to comment.