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

Add fixture with invalid encoding, update FSProject load_file to force UTF8 #420

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/licensee/projects/fs_project.rb
Expand Up @@ -44,13 +44,18 @@ def files
end
end

# Retrieve a file's content from disk
# Retrieve a file's content from disk, enforcing encoding
#
# file - the file hash, with the :name key as the file's relative path
#
# Returns the file contents as a string
def load_file(file)
File.read dir_path.join(file[:dir], file[:name])
content = File.read dir_path.join(file[:dir], file[:name])
content.force_encoding(ProjectFiles::ProjectFile::ENCODING)

return content if content.valid_encoding?

content.encode(ProjectFiles::ProjectFile::ENCODING, ProjectFiles::ProjectFile::ENCODING_OPTIONS)
end

# Returns true if @dir is @root or it's descendant
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/fixtures.yml
Expand Up @@ -116,6 +116,10 @@ readme:
key: mit
matcher:
hash:
readme-invalid-encoding:
key: mit
matcher:
hash:
unlicense-noinfo:
key: unlicense
matcher: exact
Expand Down
24 changes: 24 additions & 0 deletions spec/fixtures/readme-invalid-encoding/README.md
@@ -0,0 +1,24 @@
# Readme fixture

## License

Copyright (c) 2016 Ben Balter

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.
��