harvard-lil / h2o

H2O is a web app for creating and reading open educational resources, primarily in the legal field
https://opencasebook.org
GNU Affero General Public License v3.0
35 stars 30 forks source link

Never return a null value as a link title; fixes #2005 #2010

Closed lizadaly closed 1 year ago

lizadaly commented 1 year ago

If a link requested from the frontend has an empty HTML title element, None was returned from this function and an exception would be thrown when trying to serialize that to the database where the resource title field is non-nullable. This ensures that what comes back is a string (by default, the URL becomes the title).

(This is the kind of thing that type annotations could catch if you declare that the function should always return a string, but PyQuery just always returns a PyQuery object and pyquery.text is typed as Any.)

Tested against the actual failure case in #2005.

codecov-commenter commented 1 year ago

Codecov Report

Merging #2010 (b8a5084) into develop (50e51fc) will not change coverage. The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           develop    #2010   +/-   ##
========================================
  Coverage    76.82%   76.82%           
========================================
  Files           62       62           
  Lines         6927     6927           
========================================
  Hits          5322     5322           
  Misses        1605     1605           
Impacted Files Coverage Δ
web/main/utils.py 76.43% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.