Page MenuHomeSoftware Heritage

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

Authored by vlorentz on Jan 7 2021, 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
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 18214
Build 28113: Phabricator diff pipeline on jenkinsJenkins console · Jenkins
Build 28112: arc lint + arc unit

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.Jan 7 2021, 5:31 PM