Yaron Koren has uploaded a new change for review. https://gerrit.wikimedia.org/r/227213
Change subject: Added handling of quotes, backslashes to CargoUtils::smartParse() ...................................................................... Added handling of quotes, backslashes to CargoUtils::smartParse() Change-Id: Ia094cd41984f9d1aaf82e2e66851fefa206d493c --- M CargoUtils.php 1 file changed, 29 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo refs/changes/13/227213/1 diff --git a/CargoUtils.php b/CargoUtils.php index 2a2293d..3966fe5 100644 --- a/CargoUtils.php +++ b/CargoUtils.php @@ -186,19 +186,46 @@ return array(); } + $ignoreNextChar = false; $returnValues = array(); $numOpenParentheses = 0; + $numOpenSingleQuotes = 0; + $numOpenDoubleQuotes = 0; $curReturnValue = ''; for ( $i = 0; $i < strlen( $string ); $i++ ) { $curChar = $string{$i}; - if ( $curChar == '(' ) { + + if ( $ignoreNextChar ) { + // If previous character was a backslash, + // ignore the current one, since it's escaped. + // What if this one is a backslash too? + // Doesn't matter - it's escaped. + $ignoreNextChar = false; + } elseif ( $curChar == '(' ) { $numOpenParentheses++; } elseif ( $curChar == ')' ) { $numOpenParentheses--; + } elseif ( $curChar == '\'' ) { + if ( $numOpenSingleQuotes == 0 ) { + $numOpenSingleQuotes = 1; + } else { + $numOpenSingleQuotes = 0; + } + } elseif ( $curChar == '"' ) { + if ( $numOpenDoubleQuotes == 0 ) { + $numOpenDoubleQuotes = 1; + } else { + $numOpenDoubleQuotes = 0; + } + } elseif ( $curChar == '\\' ) { + $ignoreNextChar = true; } - if ( $curChar == $delimiter && $numOpenParentheses == 0 ) { + if ( $curChar == $delimiter && + $numOpenParentheses == 0 && + $numOpenSingleQuotes == 0 && + $numOpenDoubleQuotes == 0 ) { $returnValues[] = trim( $curReturnValue ); $curReturnValue = ''; } else { -- To view, visit https://gerrit.wikimedia.org/r/227213 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia094cd41984f9d1aaf82e2e66851fefa206d493c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Cargo Gerrit-Branch: master Gerrit-Owner: Yaron Koren <yaro...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits