Skip to content

Commit

Permalink
Merge pull request #149 from phpcr/fix_language_validation
Browse files Browse the repository at this point in the history
ensure we validate the support languages in a case insensitive way
  • Loading branch information
dbu committed May 1, 2015
2 parents c41b8d4 + e2e54f1 commit b568266
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/PHPCR/Util/Console/Command/WorkspaceQueryCommand.php
Expand Up @@ -42,7 +42,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$sql = $input->getArgument('query');
$language = strtoupper($input->getOption('language'));
$language = $input->getOption('language');
$limit = $input->getOption('limit');
$offset = $input->getOption('offset');

Expand Down
17 changes: 10 additions & 7 deletions src/PHPCR/Util/Console/Helper/PhpcrHelper.php
Expand Up @@ -152,11 +152,10 @@ public function processNode(OutputInterface $output, NodeInterface $node, array
*/
public function createQuery($language, $sql)
{
$this->validateQueryLanguage($language);
$language = $this->validateQueryLanguage($language);

$session = $this->getSession();
$qm = $session->getWorkspace()->getQueryManager();
$language = strtoupper($language);
$query = $qm->createQuery($sql, $language);

return $query;
Expand All @@ -173,11 +172,15 @@ protected function validateQueryLanguage($language)
{
$qm = $this->getSession()->getWorkspace()->getQueryManager();
$langs = $qm->getSupportedQueryLanguages();
if (!in_array($language, $langs)) {
throw new \Exception(sprintf(
'Query language "%s" not supported, available query languages: %s',
$language, implode(',', $langs)
));
foreach ($langs as $lang) {
if (strtoupper($lang) === strtoupper($language)) {
return $lang;
}
}

throw new \Exception(sprintf(
'Query language "%s" not supported, available query languages: %s',
$language, implode(',', $langs)
));
}
}

0 comments on commit b568266

Please sign in to comment.