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

FindSupport is not able to handle bytes data #406

icemac opened this issue Nov 28, 2018 · 1 comment


Copy link

commented Nov 28, 2018

If PrincipiaSearchSource is called on a File or an Image it returns bytes but the search string is text which leads to an to TypeError: a bytes-like object is required, not 'str' in

obj_searchterm in ob.PrincipiaSearchSource()) or

The same exception might happen two lines later on in

obj_searchterm in ob.SearchableText())

But I did not try to provoke it.

I am not sure what a good solution can be:

  • Should PrincipiaSearchSource always return text? (If the object contains binary data it should return an empty text?)
  • Should the call in FindSupport only made if PrincipiaSearchSource returned text?
  • Same for SearchableText – but this might be a bit easier to answer as the method contains text in its name.

@icemac icemac added this to the 4.0 final milestone Nov 28, 2018

@icemac icemac added this to To do in Zope 4 final release via automation Nov 28, 2018

@icemac icemac changed the title FindSupport is not able to handle bytes data FindSupport is not able to handle byte data Nov 28, 2018

@icemac icemac changed the title FindSupport is not able to handle byte data FindSupport is not able to handle bytes data Nov 28, 2018


This comment has been minimized.

Copy link

commented Feb 2, 2019

Both PrincipiaSearchSource and SearchableText make no effort to coerce the return value to any specific kind of string, they just blindly return what they get e.g. after reading a file. The implementation in OFS.File will at least check a file's content type and only return anything if the major type is text.

There may be many implementations of both PrincipiaSearchSource and SearchableText out there and we can't control/fix them all. My vote would be for adding checks inside FindSupport that try to decode binary data with e.g. the ZPublisher default encoding. If it can be decoded that way we use it, if not we disregard it for the search.

@dataflake dataflake self-assigned this Feb 2, 2019

Zope 4 final release automation moved this from To do to Done Mar 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.