Skip to content

Handle string repository and string authors in bower.json (fixes #5543) - #5544

Open
muskan-creates352 wants to merge 1 commit into
aboutcode-org:developfrom
muskan-creates352:fix-bower-repository-and-authors-5543
Open

muskan-creates352 wants to merge 1 commit into
aboutcode-org:developfrom
muskan-creates352:fix-bower-repository-and-authors-5543

Conversation

@muskan-creates352

Copy link
Copy Markdown

Summary

This PR fixes an unhandled AttributeError: 'str' object has no attribute 'get' in BowerJsonHandler when repository is defined as a string, ensures vcs_url is retained when repository is an object without a type field, and prevents string authors from being split into single-character parties (fixes #5543).

Problem

  1. In src/packagedcode/bower.py:

    repository = package_data.get('repository') or {}
    repo_type = repository.get('type')
    repo_url = repository.get('url')

    According to the Bower JSON specification, repository can be a String or an Object. When it is a string (e.g. "https://github.com/owner/repo.git"), calling repository.get('type') crashes with AttributeError.
    Furthermore, when repository is an object with only url (no type), vcs_url was dropped because of if repo_type and repo_url:.

  2. The specification also defines authors as Array of (String or Object) or String. When authors is a string (e.g. "authors": "Jane Doe"), for author in authors: iterated over individual characters, creating separate Party entries for every single letter (Party(name='J'), Party(name='a'), etc.).

Changes

  • In src/packagedcode/bower.py:
    • Check whether repository is a str or dict. If str, set vcs_url = repository. If dict, extract type and url, falling back to url if type is missing.
    • Normalize authors into a list if it is passed as a string or dict, and also accept author (singular).
  • In tests/packagedcode/test_bower.py:
    • Added unit test for string repository.
    • Added unit test for dict repository without type.
    • Added unit test for string authors.
    • Added unit test for single author key.
    • All 10 tests in test_bower.py pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] BowerJsonHandler crashes with AttributeError when repository is a string and splits string authors into single characters

1 participant