Page MenuHomeSoftware Heritage

Fix TypeError caused by empty lists being passed as a string to re.sub.
ClosedPublic

Authored by vlorentz on Thu, Jan 7, 5:20 PM.

Details

Summary

In make_api_response, empty lists were not JSONized because they were
mistakenly detected as a None, which caused these empty lists to be
passed to urlize_links_and_mails, which expects strings.

It caused a TypeError when calling re.sub() on it, which was catched
so it still returned a result (and a correct one, since empty lists
don't need substitution).

This commit removes the catch workaround and always passes the right
type.

Resolves Sentry issue SWH-WEBAPP-H1

Test Plan

already covered by tests.

Diff Detail

Repository
rDWAPPS Web applications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build is green

Patch application report for D4819 (id=17073)

Rebasing onto 2ed38516a4...

Current branch diff-target is up to date.
Changes applied before test
commit 6f8b844070d82cd18675a05fbf9e07973622b271
Author: Valentin Lorentz <vlorentz@softwareheritage.org>
Date:   Thu Jan 7 17:19:45 2021 +0100

    Fix TypeError caused by empty lists being passed as a string to re.sub.
    
    In make_api_response, empty lists were not JSONized because they were
    mistakenly detected as a None, which caused these empty lists to be
    passed to urlize_links_and_mails, which expects strings.
    
    It caused a TypeError when calling re.sub() on it, which was catched
    so it still returned a result (and a correct one, since empty lists
    don't need substitution).
    
    This commit removes the catch workaround and always passes the right
    type.

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/546/ for more details.

anlambert added a subscriber: anlambert.

Thanks for that fix !

This revision is now accepted and ready to land.Thu, Jan 7, 5:31 PM