Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize case sensitivity for matching entities and filtering commits #1444

Closed
wants to merge 6 commits into from

Conversation

pavelevap
Copy link
Collaborator

Resolves #1439

Case-insensitive comparison moved from QueryLanguageUtils::createRulesFromQueries and QueryLanguageUtils::entityMatchesSomeRule to QueryLanguageUtils::createGitLogQueryFromRule. This ensures that entities comparison will be case-sensitive and filtering commits case-insensitive without losing any information related to capitalized characters.

Remove strtolower() from createRulesFromQueries() and entityMatchesSomeRule() to avoid case insensitivity for processing entities. Add strtolower() to createGitLogQueryFromRule() to ensure case insensitivity for converting rules related to filtering commits.
Processing entities should be case-sensitive, but converting rules for git log queries should be case-insensitive.
} else {
$prefix = '\(X-VP-\|VP-\)';
$key = '\(X-VP-\|VP-\)' . $key;
Copy link
Collaborator Author

@pavelevap pavelevap May 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stayed with capitalized characters here and changed queryLanguageUtilsGeneratesCorrectGitLogQuery test accordingly to follow VP-Action example (also capitalized letters) and made some small changes to allowing test to pass (assertEquals() is now case sensitive). But it can be also switched to lowercase characters.

@pavelevap pavelevap self-assigned this May 12, 2019
@borekb
Copy link
Member

borekb commented May 14, 2019

This ensures that entities comparison will be case-sensitive

Is that the goal though? I think the intent of #1439 was to:

  • Update query parsing so that it maintains the original letter casing, i.e., it doesn't lose any information when translating from YAML to PHP.
  • Implement case insensitivity suitably for each scenario:
    • For Git searching, use git log -i flag.
    • For entity comparison, use strtolower in entityMatchesSomeRule (or similar; the key point is that the comparison is case insensitive).

Importantly, this would not change any user-facing behavior, just organize the code better and also fix the tests (for example, this change is highly desirable: https://github.com/versionpress/versionpress/pull/1444/files#diff-c2ff5a3b77d21156b05214cdb94eb655R107). If we keep case insensitivity as far as the user is concerned, many things in this PR will become simpler.

@pavelevap
Copy link
Collaborator Author

For entity comparison, use strtolowercase in entityMatchesSomeRule.

Yes, you are right, I see it now. I probably moved the goal a little bit for this part. During work on this PR I realized that we also do not need using strtolower() in QueryLanguageUtils::entityMatchesSomeRule and we can compare entities case-sensitive (and also avoid problems with missing multibyte string functions). It leads me to use strtolower() for array keys in QueryLanguageUtils::createGitLogQueryFromRule to fix converting rules for git log and remove restriction on case insensitivity for some QueryLanguageUtilsTest.

For Git searching is still used git log -i flag (checked manually), PR only fixes differences between QueryLanguageUtils::createGitLogQueryFromRule and related test. Also query parsing maintains the original letter casing now.

@borekb
Copy link
Member

borekb commented May 15, 2019

Yes, this PR does many good things and I think it's about 80% where it should be. It just wasn't clear to me what the goal regarding entity matching was as the issue mentions docs and their necessary update around "queries use the same syntax as search / filtering in the UI" – #1439 (comment).

BTW, I've updated my previous comment to highlight that strtolower is just an example; you're right that there might be better implementations.

Copy link
Member

@borekb borekb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pavelevap, following up on the discussion starting with #1444 (comment), I left some comments directly in code to demonstrate what I meant. Hopefully we're on the same page.

@@ -128,7 +128,7 @@ public function ignoredEntityCapitalizedIsCorrectlyIdentified()
$entity = [
'some_field' => 'b',
'other_field' => 'a',
'capitalized_value_field' => 'VaLuE', // comparison must be case insensitive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how the test should look – we indeed want to test that if VaLuE is provided, it is still matched by a rule that uses uppercase (or lowercase, or any-case) VALUE.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we are providing VALUE in original $entitySchema, so we are also expecting VALUE. Comparison is not case insensitive now, so VaLuE would fail.

@@ -101,8 +104,7 @@ public function ruleAndQueryProvider()
public function queryLanguageUtilsCreatesCorrectRules($query, $expectedRules)
{
$rules = QueryLanguageUtils::createRulesFromQueries($query);
// Perform case insensitive match
$this->assertEquals($expectedRules, $rules, '', 0, 10, false, true);
$this->assertEquals($expectedRules, $rules);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this is a very welcome change, basically making tests actually test something :)

[['x-vp-another-key' => ['Test value']], '-i --all-match --grep="^x-vp-another-key: \(Test value\)$"'],
[['vp-another-key' => ['Test value']], '-i --all-match --grep="^\(x-\)\?vp-another-key: \(Test value\)$"'],
[['another-key' => ['Test value']], '-i --all-match --grep="^\(x-vp-\|vp-\)another-key: \(Test value\)$"'],
[['X-vp-another-key' => ['Test value']], '-i --all-match --grep="^X-VP-another-key: \(Test value\)$"'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that no case juggling is necessary here. If the input is X-vp-another-key, Git search should be ... --grep="^X-vp-another-key as well.

Similarly for the lines below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we need it for QueryLanguageUtils::createGitLogQueryFromRule and also this test (and I believe that it was the original reason to make tests case-insensitive before).
Example: vp-another-key was automatically transformed into X-vp-another-key and test would fail because of expecting x-vp-another-key.


Result will be now capitalized everytime: X-VP-another-key (see changes in QueryLanguageUtils::createGitLogQueryFromRule). But I am not sure if this is the best solution, see my previous comment: #1444 (review).

@pavelevap
Copy link
Collaborator Author

I am closing this PR, superseded by #1450.

@pavelevap pavelevap closed this Jun 25, 2019
@pavelevap pavelevap deleted the 1439-rethink-case-sensitivity branch June 25, 2019 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rethink case sensitivity comparison for entities
2 participants