Skip to content

33589 fix array values in catalogsearch parameters #33682

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

Conversation

SilinMykola
Copy link
Contributor

Description (*)

I changed a method that prepare values for advanced search. Model: \Magento\CatalogSearch\Model\Advanced

Fixed Issues (if relevant)

  1. Fixes strlen() expects parameter 1 to be string, array given | magento/module-catalog-search #33589

Manual testing scenarios (*)

  1. Open page with parameters: /catalogsearch/advanced/result/?price[from][]=1&price[to]=1
    For example: htps://base_url/catalogsearch/advanced/result/?price[from][]=1&price[to]=1

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Aug 4, 2021

Hi @SilinMykola. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-community-project m2-community-project bot added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Aug 4, 2021
@magento-engcom-team magento-engcom-team added Component: CatalogSearch Release Line: 2.4 Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner labels Aug 4, 2021
@SilinMykola
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@andrewbess
Copy link
Contributor

@magento give me test instance

@magento-deployment-service
Copy link

Hi @andrewbess. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

Hi @andrewbess, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

Copy link
Contributor

@eduard13 eduard13 left a comment

Choose a reason for hiding this comment

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

Hi @SilinMykola, could you please cover these changes by an integration test?

Thank you.

@andrewbess
Copy link
Contributor

@magento give me test instance

@magento-deployment-service
Copy link

Hi @andrewbess. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@andrewbess
Copy link
Contributor

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@SilinMykola
Copy link
Contributor Author

Hi @SilinMykola, could you please cover these changes by an integration test?

Thank you.

Hi! @eduard13 ! Ok, I'll create integration test for this model.

@eduard13
Copy link
Contributor

eduard13 commented Aug 5, 2021

@SilinMykola, additionally, could you please check how the catalogsearch/result handles such cases?
Thanks.

Comment on lines 371 to 376
if (is_array($value['from'])) {
$value['from'] = $this->getFirstArrayElement($value['from']);
}
if (is_array($value['to'])) {
$value['to'] = $this->getFirstArrayElement($value['to']);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, in case if we got an incorrect type - it's better to do assume that this parameter doesn't exist at all. I think we're expecting here the only string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ihor-sviziev Hi! May be you are right and we should create a redirect if $value['from'] or $value['to'] is array. But I think we can check this arrays for some values and create a valid response.

cc: @andrewbess, @eduard13

Copy link
Contributor

Choose a reason for hiding this comment

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

@SilinMykola I'm agree with @ihor-sviziev that we should ignore this parameter if it's not valid instead of trying to understand what we received and extract some data from it.
Looks like patch for all occasions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, @Den4ik! Locally I removed this code and work on tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

The following comment is related to this discussion #33589 (comment)

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@Den4ik
Copy link
Contributor

Den4ik commented Aug 24, 2021

@SilinMykola Please check failed integration tests

@SilinMykola
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@SilinMykola
Copy link
Contributor Author

@magento run Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

Copy link
Contributor

@Den4ik Den4ik left a comment

Choose a reason for hiding this comment

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

After discussion with @SilinMykola in slack and test possible one another solution I approve this PR as easiest an fast solution for now.
@SilinMykola Thanks for the work

@magento-engcom-team
Copy link
Contributor

Hi @Den4ik, thank you for the review.
ENGCOM-9197 has been created to process this Pull Request
✳️ @Den4ik, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@Den4ik Den4ik added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Aug 25, 2021
@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-9197 has been created to process this Pull Request

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Preconditions:

  1. Install fresh Magento instance with sample data.

Manual testing scenario:

  1. Front end: Click on "advanced search" link from the footer.

  2. Set the price 1 to 1 and do search

  3. Edit the resulted URL from /***/advanced/result/?name=&sku=&description=&short_description=&price%5Bfrom%5D=1&price%5Bto%5D=1 to /***/advanced/result/?price[from][]=1&price[to]=1

  4. Validate the edited URL response in the web page.

Before: ✖️ Used to get an error message

image

After: ✔️ Gives the search result information

With no result data
image

With result data
image

There is no additional regression is required since it is a specific case where we are doing an URL tampering. It has no impact on any other features as well.

@m2-assistant
Copy link

m2-assistant bot commented Sep 23, 2021

Hi @SilinMykola, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@SilinMykola SilinMykola deleted the 33589-catalogsearch-strlen-exception branch September 23, 2021 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: CatalogSearch Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

strlen() expects parameter 1 to be string, array given | magento/module-catalog-search
7 participants