Skip to content

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

Merged
Hook25 merged 3 commits intomainfrom
hotfix-empty-slugify
Mar 5, 2025
Merged

Fix slugify when str is empty/none (BugFix)#1768
Hook25 merged 3 commits intomainfrom
hotfix-empty-slugify

Conversation

@pedro-avalos
Copy link
Copy Markdown
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
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.63%. Comparing base (ab07f21) to head (4425e59).
Report is 120 commits behind head on main.

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 ∅ <100.00%> (∅)

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Hook25
Copy link
Copy Markdown
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
@Hook25 Hook25 merged commit ce7b4f9 into main Mar 5, 2025
21 checks passed
@Hook25 Hook25 deleted the hotfix-empty-slugify branch March 5, 2025 08:36
stanley31huang pushed a commit that referenced this pull request Mar 28, 2025
* Fix slugify when str is empty/none

* Return _string instead of "_"

* Fix tests
mreed8855 pushed a commit that referenced this pull request Jul 31, 2025
* Fix slugify when str is empty/none

* Return _string instead of "_"

* Fix tests
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