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

Facebook-style params don't work if a facet pivot is configured #3512

Closed
sandbergja opened this issue Feb 12, 2025 · 5 comments · Fixed by #3514
Closed

Facebook-style params don't work if a facet pivot is configured #3512

sandbergja opened this issue Feb 12, 2025 · 5 comments · Fixed by #3514
Assignees

Comments

@sandbergja
Copy link
Contributor

sandbergja commented Feb 12, 2025

Background

When somebody posts a blacklight search containing a facet to Facebook, facebook rewrites the URL in an odd way:

http://localhost:3000/?f[format][]=Book

becomes

http://localhost:3000/?f[format][0]=Book

These types of URLs have caused issues in Blacklight a few different times, see #1785, #2313, and #2654 . It's cropped up again, this time only erroring if you have a pivot facet configured.

Steps to recreate

  1. Set up blacklight running locally using these instructions
  2. Go to http://localhost:3000/?f[format][0]=Book
  3. Note that you get undefined method '-' for {"0"=>"Book"}:ActiveSupport::HashWithIndifferentAccess
  4. Remove the pivot facet from .internal_test_app/app/controllers/catalog_controller.rb
  5. Go to http://localhost:3000/?f[format][0]=Book
  6. Note that it works just fine!
@jrochkind
Copy link
Member

Thanks for reporting this. Just for more context, I've dealt with this in my local app by catching these facebook-rewritten ones and rewriting them back. Not sure that's the best solution, it's just the hack I did on noticing this.

https://github.com/sciencehistory/scihist_digicoll/blob/f43b73f08eb90db7167665554ef4e681cdac7d13/app/controllers/catalog_controller.rb#L7

https://github.com/sciencehistory/scihist_digicoll/blob/f43b73f08eb90db7167665554ef4e681cdac7d13/app/controllers/catalog_controller.rb#L586-L603

@jrochkind
Copy link
Member

jrochkind commented Feb 12, 2025

So i noticed my notes said I expected this PR to fix it though!

#2313

And it does have a comment "Normalize facet parameters mangled by facebook"

That was merged in 2020, so apparently hasn't fixed it?

Or, it looks like that commit is included in Blacklight's 7.11.0 and following; are you encountering this on an earlier version of blacklight?

If this hasn't fixed it, we shoudl figure out why tests didn't catch that, and make sure to fix them to!

@sandbergja
Copy link
Contributor Author

sandbergja commented Feb 12, 2025

I see this on main and release-8.x, @jrochkind

This test does not catch it because it does not have a pivot facet in the test setup. If you add the following to the before block, you will get a test failure: blacklight_config.add_facet_field 'some_other_pivot_field', pivot: ['abc']

And we don't appear to have any feature tests that cover this type of params.

@jrochkind
Copy link
Member

Cool, so the identified code above, already in BL intending to handle the Facebook-mangled URLs, is perhaps not sufficient to fix it for some uses cases -- sounds like maybe for pivot facets specifically? And needs to be improved, with test changed/added to prevent regression?

Does this seem right?

(I don't know much about pivot facets personally).

@sandbergja
Copy link
Contributor Author

Sounds right to me, @jrochkind !

sandbergja added a commit that referenced this issue Feb 20, 2025
…vot is configured

each_with_object ignores the return value of the supplied block; you need to mutate
the passed object instead.

Prior to this change, the ramifications of bug are that:
* FilterField#permitted_params always includes empty hashes (the original, unmutated
  object we passed to each_with_object) for a facet pivot field.
* When Blacklight::Parameters::deep_merge_permitted_params comes across empty hashes,
  it discards a present hash in favor of the empty one.
* As the permitted params for all facet fields are merged together, the presence of
  even one facet pivot field leads us to discard all other permitted facet field keys.
* We have empty hashes, rather than hashes with permitted facet keys going into
  Blacklight::Parameters#deep_unmangle_params!
* Blacklight::Parameters#deep_unmangle_params! can find no permitted parameters that
  it needs to unmangle, so the facebook params never get unmangled, causing errors
  and unexpected behavior elsewhere in the stack.
* Facebook-style query params don't work if a facet pivot is configured.
sandbergja added a commit that referenced this issue Feb 21, 2025
…vot is configured

each_with_object ignores the return value of the supplied block; you need to mutate
the passed object instead.

Prior to this change, the ramifications of bug are that:
* FilterField#permitted_params always includes empty hashes (the original, unmutated
  object we passed to each_with_object) for a facet pivot field.
* When Blacklight::Parameters::deep_merge_permitted_params comes across empty hashes,
  it discards a present hash in favor of the empty one.
* As the permitted params for all facet fields are merged together, the presence of
  even one facet pivot field leads us to discard all other permitted facet field keys.
* We have empty hashes, rather than hashes with permitted facet keys going into
  Blacklight::Parameters#deep_unmangle_params!
* Blacklight::Parameters#deep_unmangle_params! can find no permitted parameters that
  it needs to unmangle, so the facebook params never get unmangled, causing errors
  and unexpected behavior elsewhere in the stack.
* Facebook-style query params don't work if a facet pivot is configured.

Co-authored-by: Christina Chortaria <christinach@users.noreply.github.com>
sandbergja added a commit that referenced this issue Feb 24, 2025
…vot is configured (#3514)

each_with_object ignores the return value of the supplied block; you need to mutate
the passed object instead.

Prior to this change, the ramifications of bug are that:
* FilterField#permitted_params always includes empty hashes (the original, unmutated
  object we passed to each_with_object) for a facet pivot field.
* When Blacklight::Parameters::deep_merge_permitted_params comes across empty hashes,
  it discards a present hash in favor of the empty one.
* As the permitted params for all facet fields are merged together, the presence of
  even one facet pivot field leads us to discard all other permitted facet field keys.
* We have empty hashes, rather than hashes with permitted facet keys going into
  Blacklight::Parameters#deep_unmangle_params!
* Blacklight::Parameters#deep_unmangle_params! can find no permitted parameters that
  it needs to unmangle, so the facebook params never get unmangled, causing errors
  and unexpected behavior elsewhere in the stack.
* Facebook-style query params don't work if a facet pivot is configured.

Co-authored-by: Christina Chortaria <christinach@users.noreply.github.com>
sandbergja added a commit that referenced this issue Feb 24, 2025
…vot is configured (#3514)

each_with_object ignores the return value of the supplied block; you need to mutate
the passed object instead.

Prior to this change, the ramifications of bug are that:
* FilterField#permitted_params always includes empty hashes (the original, unmutated
  object we passed to each_with_object) for a facet pivot field.
* When Blacklight::Parameters::deep_merge_permitted_params comes across empty hashes,
  it discards a present hash in favor of the empty one.
* As the permitted params for all facet fields are merged together, the presence of
  even one facet pivot field leads us to discard all other permitted facet field keys.
* We have empty hashes, rather than hashes with permitted facet keys going into
  Blacklight::Parameters#deep_unmangle_params!
* Blacklight::Parameters#deep_unmangle_params! can find no permitted parameters that
  it needs to unmangle, so the facebook params never get unmangled, causing errors
  and unexpected behavior elsewhere in the stack.
* Facebook-style query params don't work if a facet pivot is configured.

Co-authored-by: Christina Chortaria <christinach@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants