@@ -81,27 +81,37 @@ trait RichConfigOps extends Dynamic with LowPriorityArgs4cImplicits {
8181 * @return a configuration with the given user-argument overrides applied over top
8282 */
8383 def withUserArgs (args : Array [String ], unrecognizedArg : String => Config = ParseArg .Throw ): Config = {
84- def isSimpleList (key : String ) = {
85- def isList = Try (config.getStringList(key)).isSuccess
84+ def isValidKey (key : String ): Boolean = {
85+ try {
86+ config.hasPath(key)
87+ } catch {
88+ case _ : ConfigException => false
89+ }
90+ }
8691
92+ def isSimpleList (key : String ): Boolean = {
93+ def isList = Try (config.getStringList(key)).isSuccess
8794 config.hasPath(key) && isList
8895 }
8996
9097 def isObjectList (key : String ) = {
9198 def isList = Try (config.getObjectList(key)).isSuccess
92-
9399 config.hasPath(key) && isList
94100 }
95101
96102 val configs : Array [Config ] = args.map {
97- case KeyValue (k, v) if isSimpleList(k) =>
103+ case KeyValue (k, v) if isValidKey(k) && isSimpleList(k) =>
98104 asConfig(k, java.util.Arrays .asList(v.split(" ," , - 1 ): _* ))
99- case KeyValue (k, v) if isObjectList(k) =>
105+ case KeyValue (k, v) if isValidKey(k) && isObjectList(k) =>
100106 sys.error(s " Path ' $k' tried to override an object list with ' $v' " )
101- case KeyValue (k, v) => asConfig(k, v)
102- case FilePathConfig (c) => c
103- case UrlPathConfig (c) => c
104- case other => unrecognizedArg(other)
107+ case KeyValue (k, v) if isValidKey(k) => asConfig(k, v)
108+ case FilePathConfig (c) => c
109+ case UrlPathConfig (c) => c
110+ case other @ KeyValue (k, v) =>
111+ val safeKey = ConfigUtil .quoteString(k)
112+ asConfig(safeKey, v)
113+ case other =>
114+ unrecognizedArg(other)
105115 }
106116
107117 (configs :+ config).reduce(_ withFallback _)
0 commit comments