-
-
Notifications
You must be signed in to change notification settings - Fork 91
Handle misencoded license text files graceful. #884
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
01c8854
feat: Handle misencoded license text files graceful.
0a39e86
tests: tests for the code
35b752c
Refactor and simplify
373254c
Simplify conditions and loop
4ff9b23
Look into locations subdir
d95dc73
tests: rearranged tests
jkowalleck 62559a7
tests: rearranged tests
jkowalleck 78133ab
tests: rearranged tests
jkowalleck d2aa2ba
fix: try to detect licensetexts, or pass silently
jkowalleck 4982a64
Merge pull request #1 from CycloneDX/issue_868_jk
schlenk f4ea670
tidy
jkowalleck 6e168f0
Merge remote-tracking branch 'origin/main' into issue_868
jkowalleck e256925
Merge branch 'main' into issue_868
jkowalleck 3be391d
Add better rtf mimetype
29f0488
Revert "Add better rtf mimetype"
5be4c74
Merge branch 'CycloneDX:main' into issue_868
schlenk 1bd9401
Merge branch 'main' into issue_868
jkowalleck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # This file is part of CycloneDX Python | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # Copyright (c) OWASP Foundation. All Rights Reserved. | ||
|
|
||
| from sys import getdefaultencoding | ||
|
|
||
| from chardet import detect as chardetect | ||
|
|
||
|
|
||
| def bytes2str(data: bytes, *, errors: str = 'strict') -> str: | ||
| # see https://docs.python.org/3/library/codecs.html#standard-encodings | ||
| encoding = (chardetect(data)['encoding'] or getdefaultencoding()).replace( | ||
| # replace Windows-encoding with code-page | ||
| 'Windows-', 'cp') | ||
| return data.decode(encoding, errors) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...data/infiles/_helpers/local_pckages/with-license-pep639_regression-issue868/.editorconfig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # EditorConfig is awesome: https://editorconfig.org | ||
|
|
||
| [my_licenses/utf-8*] | ||
| charset = utf-8 | ||
|
|
||
| [my_licenses/utf-16le*] | ||
| charset = utf-16le | ||
|
|
||
| [my_licenses/utf-16be*] | ||
| charset = utf-16be | ||
|
|
2 changes: 2 additions & 0 deletions
2
...ata/infiles/_helpers/local_pckages/with-license-pep639_regression-issue868/.gitattributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Licenses/* binary | ||
| Licenses/*.txt binary diff=txt |
6 changes: 6 additions & 0 deletions
6
...nfiles/_helpers/local_pckages/with-license-pep639_regression-issue868/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # PEP 639 - regression 868 | ||
|
|
||
| see <https://github.com/CycloneDX/cyclonedx-python/issues/868> | ||
|
|
||
| PEP-630 expects license gfiles to be UTF8 encoded text. | ||
| some license files may not be text, some may not be UTF8 encoded, but still be added as license files. |
Binary file added
BIN
+210 Bytes
...s/_helpers/local_pckages/with-license-pep639_regression-issue868/my_licenses/richtext.rtf
Binary file not shown.
Binary file added
BIN
+94 Bytes
...rs/local_pckages/with-license-pep639_regression-issue868/my_licenses/utf-16be_withBOM.txt
Binary file not shown.
Binary file added
BIN
+86 Bytes
...rs/local_pckages/with-license-pep639_regression-issue868/my_licenses/utf-16le_withBOM.txt
Binary file not shown.
4 changes: 4 additions & 0 deletions
4
...helpers/local_pckages/with-license-pep639_regression-issue868/my_licenses/utf-8_noBOM.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| this file is | ||
| utf-8 encoded | ||
| without BOM | ||
| 😃 |
4 changes: 4 additions & 0 deletions
4
...lpers/local_pckages/with-license-pep639_regression-issue868/my_licenses/utf-8_withBOM.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| this file is | ||
| utf-8 encoded | ||
| with BOM | ||
| 😃 |
16 changes: 16 additions & 0 deletions
16
...ata/infiles/_helpers/local_pckages/with-license-pep639_regression-issue868/pyproject.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [build-system] | ||
| # Known broken version | ||
| requires = ["setuptools == 78.1.0"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [project] | ||
| name = "regression-issue868" | ||
| version = "0.1" | ||
| license-files = ["my_licenses/*"] | ||
| readme = "README.md" | ||
|
|
||
| [tool.setuptools] | ||
| include-package-data = false | ||
| exclude-package-data = { "*" = ["*", "**"] } | ||
| [tool.setuptools.package-data] | ||
| # do not want any content installed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tests/_data/snapshots/environment/pep639-texts_with-license-pep639_1.0.xml.bin
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
tests/_data/snapshots/environment/pep639-texts_with-license-pep639_1.1.xml.bin
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
67 changes: 66 additions & 1 deletion
67
tests/_data/snapshots/environment/pep639-texts_with-license-pep639_1.2.json.bin
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.