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

Fix slugify when str is empty/none (BugFix) #1768

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pedro-avalos
Copy link
Collaborator

Description

Currently the slugify function assumes the _string argument is not empty/None. However, I saw this when trying to run some tests on hinyari. One of the device attributes was empty, but existed.

Traceback (most recent call last):
  File "/home/ubuntu/checkbox/providers/resource/bin/udev_resource.py", line 198, in <module>
    main()
  File "/home/ubuntu/checkbox/providers/resource/bin/udev_resource.py", line 194, in main
    dump_udev_db(udev)
  File "/home/ubuntu/checkbox/providers/resource/bin/udev_resource.py", line 76, in dump_udev_db
    value = getattr(device, attribute)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/checkbox_support/parsers/udevadm.py", line 933, in vendor_slug
    return slugify(self.vendor)
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/checkbox_support/helpers/slugify.py", line 33, in slugify
    if _string[0].isdigit():

Resolved issues

Documentation

Tests

Added a unit test

@pedro-avalos pedro-avalos added the bug Something isn't working label Mar 3, 2025
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.63%. Comparing base (7faa421) to head (6c5f174).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1768   +/-   ##
=======================================
  Coverage   49.63%   49.63%           
=======================================
  Files         377      377           
  Lines       40628    40630    +2     
  Branches     6829     6830    +1     
=======================================
+ Hits        20166    20168    +2     
  Misses      19740    19740           
  Partials      722      722           
Flag Coverage Δ
checkbox-support 62.01% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hook25
Copy link
Collaborator

Hook25 commented Mar 4, 2025

Uhm this is a bit dangerous, None and "" would expand to the same symbol that is not even "". The semantic here is not clear at all imo. What if we introduce a kwarg with a default value simmilar to dict.get for a default when the string is None? For "" I would expect "" to be the expansion, similarly to what str.capitalize does for example

@pedro-avalos pedro-avalos force-pushed the hotfix-empty-slugify branch from c76a48c to 4425e59 Compare March 4, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants