@@ -108,17 +108,28 @@ private function addRecurringJobs(OutputInterface $output)
108108 }
109109
110110 $ command = $ configuration ->getCommand ();
111- $ arguments = [];
112111
113- // i.e. does the command already have options or arguments within the string
114112 if (stripos ($ configuration ->getCommand (), ' ' ) !== false ) {
115- $ command = trim (strstr ($ configuration ->getCommand (), ' ' , true ));
116- $ arguments = explode (' ' , trim (strstr ($ configuration ->getCommand (), ' ' , false )));
113+ throw new \LogicException (sprintf ('%s Command cannot contain spaces ' , $ configuration ->getCommand ()));
114+ }
115+
116+ foreach ($ configuration ->getArguments () as $ argument ) {
117+ if (!is_string ($ argument )) {
118+ throw new \Exception ('Argument was expected to be a string ' );
119+ }
120+
121+ $ this ->validateNoQuotes ($ argument , $ configuration );
122+
123+ if (substr ($ argument , 0 , 2 ) === '-- ' ) {
124+ $ optionValue = ltrim (strstr ($ argument , '= ' ), '= ' );
125+
126+ $ this ->validateNoQuotes ($ optionValue , $ configuration );
127+ }
117128 }
118129
119130 $ this ->jobManager ->addConsoleCommandJob (
120131 $ command ,
121- $ arguments ,
132+ $ configuration -> getArguments () ,
122133 $ configuration ->getTopic (),
123134 $ configuration ->getTimeout (),
124135 $ configuration ->getTimeout ()
@@ -141,4 +152,23 @@ private function maintainJobLogs()
141152 {
142153 $ this ->jobLogRepository ->removeExpiredJobs ();
143154 }
155+
156+ /**
157+ * @param string $argument
158+ * @param RecurringConsoleCommandConfiguration $configuration
159+ * @throws \Exception
160+ */
161+ private function validateNoQuotes (string $ argument , RecurringConsoleCommandConfiguration $ configuration ): void
162+ {
163+ $ firstCharacter = substr ($ argument , 0 , 1 );
164+ $ lastCharacter = substr ($ argument , strlen ($ argument )-1 , 1 );
165+
166+ if ($ firstCharacter === '" ' && $ lastCharacter === '" ' ) {
167+ throw new \Exception (sprintf ('remove quotes as they will be included as literal values on %s ' , $ configuration ->getCommand ()));
168+ }
169+
170+ if ($ firstCharacter === "' " && $ lastCharacter === "' " ) {
171+ throw new \Exception (sprintf ('remove quotes as they will be included as literal values on %s ' , $ configuration ->getCommand ()));
172+ }
173+ }
144174}
0 commit comments