diff --git a/Project.toml b/Project.toml index d89080a..fe1b714 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LicenseCheck" uuid = "726dbf0d-6eb6-41af-b36c-cd770e0f00cc" authors = ["Eric P. Hanson"] -version = "0.2.0" +version = "0.2.1" [deps] licensecheck_jll = "4ecb348a-8b88-51ea-b912-4c460483ee91" diff --git a/src/find_licenses.jl b/src/find_licenses.jl index 4054d09..3172e30 100644 --- a/src/find_licenses.jl +++ b/src/find_licenses.jl @@ -30,7 +30,9 @@ function license_table(dir, names; validate_strings = true, validate_paths = tru path = joinpath(dir, lic) validate_paths && (isfile(path) || continue) text = read(path, String) - validate_strings && (isvalid(String, text) || continue) + # In licensecheck we're going to convert the string to a `Cstring` with + # `unsafe_convert`, so the string can't have any NUL character + validate_strings && ((isvalid(String, text) && !Base.containsnul(text)) || continue) lc = licensecheck(text) if lc.license_file_percent_covered > 0 push!(table, (; license_filename=lic, lc...)) diff --git a/test/nul_string_dir/LICENSE b/test/nul_string_dir/LICENSE new file mode 100644 index 0000000..9e2aae2 --- /dev/null +++ b/test/nul_string_dir/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Eric P. Hanson + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/nul_string_dir/file_with_nul_in_the_middle.txt b/test/nul_string_dir/file_with_nul_in_the_middle.txt new file mode 100644 index 0000000..b5b1922 Binary files /dev/null and b/test/nul_string_dir/file_with_nul_in_the_middle.txt differ diff --git a/test/runtests.jl b/test/runtests.jl index 031e171..5f69e1a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -107,4 +107,12 @@ dorian_gray = """ results = find_licenses_by_list(joinpath(@__DIR__, "..")) @test fl ∈ results end + + @testset "AnalyzeRegistry#14" begin + fl = find_license("nul_string_dir") + @test fl.license_filename == "LICENSE" + @test fl.licenses_found == ["MIT"] + @test fl.license_file_percent_covered > 90 + @test_throws ArgumentError LicenseCheck.license_table("nul_string_dir", ["file_with_nul_in_the_middle.txt"]; validate_strings = false) + end end