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

Gracefully handle files with UTF-8 BOM #225

Merged
merged 3 commits into from
Jan 14, 2016
Merged

Gracefully handle files with UTF-8 BOM #225

merged 3 commits into from
Jan 14, 2016

Conversation

bkeepers
Copy link
Owner

Reported in #224, and as @SuriyaaKudoIsc points out, the Unicode byte order mark is used to identify which encoding is being used. This updates dotenv to properly handle the BOM using Ruby's built-in encoding support.

@SuriyaaKudoIsc can you test this out on for me? You should be able to add this to your gemfile:

gem "dotenv", github: "bkeepers/dotenv", branch: "bom"

This should fix #224

@suriyaa
Copy link

suriyaa commented Nov 30, 2015

@bkeepers:

Doesn't work for me with Bundler (I run cmd with admin rights!):

C:\Users\Suriyaa\Downloads\platform-samples\api\ruby\basics-of-authentication>bu
ndle install
DL is deprecated, please use Fiddle
Updating git://github.com/bkeepers/dotenv.git
fatal: '/cygdrive/c/Users/Suriyaa/Downloads/platform-samples/api/ruby/basics-of-
authentication/C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/cache/bundler/git
/dotenv-144e50b5b44d79bf4881c97e23671703b3ecbdf0' does not appear to be a git re
pository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Retrying git clone --no-checkout --quiet "C:/RailsInstaller/Ruby2.1.0/lib/ruby/g
ems/2.1.0/cache/bundler/git/dotenv-144e50b5b44d79bf4881c97e23671703b3ecbdf0" "C:
/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/bundler/gems/dotenv-4d3224523a67"
due to error (2/4): Bundler::Source::Git::GitCommandError Git error: command `gi
t clone --no-checkout --quiet "C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/c
ache/bundler/git/dotenv-144e50b5b44d79bf4881c97e23671703b3ecbdf0" "C:/RailsInsta
ller/Ruby2.1.0/lib/ruby/gems/2.1.0/bundler/gems/dotenv-4d3224523a67"` in directo
ry C:/Users/Suriyaa/Downloads/platform-samples/api/ruby/basics-of-authentication
 has failed.
If this error persists you could try removing the cache directory 'C:/RailsInsta
ller/Ruby2.1.0/lib/ruby/gems/2.1.0/cache/bundler/git/dotenv-144e50b5b44d79bf4881
c97e23671703b3ecbdf0'
fatal: '/cygdrive/c/Users/Suriyaa/Downloads/platform-samples/api/ruby/basics-of-
authentication/C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/cache/bundler/git
/dotenv-144e50b5b44d79bf4881c97e23671703b3ecbdf0' does not appear to be a git re
pository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Retrying git clone --no-checkout --quiet "C:/RailsInstaller/Ruby2.1.0/lib/ruby/g
ems/2.1.0/cache/bundler/git/dotenv-144e50b5b44d79bf4881c97e23671703b3ecbdf0" "C:
/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/bundler/gems/dotenv-4d3224523a67"
due to error (3/4): Bundler::Source::Git::GitCommandError Git error: command `gi
t clone --no-checkout --quiet "C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/c
ache/bundler/git/dotenv-144e50b5b44d79bf4881c97e23671703b3ecbdf0" "C:/RailsInsta
ller/Ruby2.1.0/lib/ruby/gems/2.1.0/bundler/gems/dotenv-4d3224523a67"` in directo
ry C:/Users/Suriyaa/Downloads/platform-samples/api/ruby/basics-of-authentication
 has failed.
If this error persists you could try removing the cache directory 'C:/RailsInsta
ller/Ruby2.1.0/lib/ruby/gems/2.1.0/cache/bundler/git/dotenv-144e50b5b44d79bf4881
c97e23671703b3ecbdf0'
fatal: '/cygdrive/c/Users/Suriyaa/Downloads/platform-samples/api/ruby/basics-of-
authentication/C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/cache/bundler/git
/dotenv-144e50b5b44d79bf4881c97e23671703b3ecbdf0' does not appear to be a git re
pository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Retrying git clone --no-checkout --quiet "C:/RailsInstaller/Ruby2.1.0/lib/ruby/g
ems/2.1.0/cache/bundler/git/dotenv-144e50b5b44d79bf4881c97e23671703b3ecbdf0" "C:
/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/bundler/gems/dotenv-4d3224523a67"
due to error (4/4): Bundler::Source::Git::GitCommandError Git error: command `gi
t clone --no-checkout --quiet "C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/c
ache/bundler/git/dotenv-144e50b5b44d79bf4881c97e23671703b3ecbdf0" "C:/RailsInsta
ller/Ruby2.1.0/lib/ruby/gems/2.1.0/bundler/gems/dotenv-4d3224523a67"` in directo
ry C:/Users/Suriyaa/Downloads/platform-samples/api/ruby/basics-of-authentication
 has failed.
If this error persists you could try removing the cache directory 'C:/RailsInsta
ller/Ruby2.1.0/lib/ruby/gems/2.1.0/cache/bundler/git/dotenv-144e50b5b44d79bf4881
c97e23671703b3ecbdf0'
fatal: '/cygdrive/c/Users/Suriyaa/Downloads/platform-samples/api/ruby/basics-of-
authentication/C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/cache/bundler/git
/dotenv-144e50b5b44d79bf4881c97e23671703b3ecbdf0' does not appear to be a git re
pository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Git error: command `git clone --no-checkout --quiet
"C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/cache/bundler/git/dotenv-144e50
b5b44d79bf4881c97e23671703b3ecbdf0"
"C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/bundler/gems/dotenv-4d3224523a6
7"`
in directory
C:/Users/Suriyaa/Downloads/platform-samples/api/ruby/basics-of-authentication
has failed.
If this error persists you could try removing the cache directory
'C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/cache/bundler/git/dotenv-144e50
b5b44d79bf4881c97e23671703b3ecbdf0'

C:\Users\Suriyaa\Downloads\platform-samples\api\ruby\basics-of-authentication>

@suriyaa
Copy link

suriyaa commented Dec 7, 2015

@bkeepers: What should I do?

@bkeepers
Copy link
Owner Author

bkeepers commented Dec 7, 2015

@SuriyaaKudoIsc It looks like there's something wrong with your ruby setup on Windows. I'm not a windows user, so I don't have any advice for you, sorry!

@suriyaa
Copy link

suriyaa commented Dec 7, 2015

@bkeepers:


Found the problem: I must use Windows PowerShell (= GitShell included in GitHub Desktop software) instead of CMD with Cygwin!


I could use this line of code:

gem "dotenv", github: "bkeepers/dotenv", branch: "bom"

or this:

gem "dotenv", :git => 'git://github.com/bkeepers/dotenv.git', branch: "bom"

The gem installed successfully. 😄 Both codes works!


Got the same warning 😟 after running ruby advanced_server.rb:

C:\Users\Suriyaa\Downloads\platform-samples\api\ruby\basics-of-authentication> ruby advanced_server.rb
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv/parser.rb:61:in `parse_line': Line "\xEF\xB
B\xBFGH_BASIC_CLIENT_ID=123456789" doesn't match format (Dotenv::FormatError)
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv/parser.rb:45:in `block in call'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv/parser.rb:44:in `each'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv/parser.rb:44:in `call'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv/parser.rb:34:in `call'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv/environment.rb:13:in `load'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv/environment.rb:9:in `initialize'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv.rb:15:in `new'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv.rb:15:in `block (2 levels) in load'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv.rb:59:in `ignoring_nonexistent_files'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv.rb:14:in `block in load'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv.rb:46:in `call'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv.rb:46:in `block in with'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv.rb:45:in `each'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv.rb:45:in `reduce'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv.rb:45:in `with'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/dotenv-2.0.2/lib/dotenv.rb:13:in `load'
        from advanced_server.rb:6:in `<main>'
C:\Users\Suriyaa\Downloads\platform-samples\api\ruby\basics-of-authentication>

bkeepers added a commit that referenced this pull request Jan 14, 2016
Gracefully handle files with UTF-8 BOM
@bkeepers bkeepers merged commit c44af19 into master Jan 14, 2016
@bkeepers bkeepers deleted the bom branch July 26, 2022 17:14
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.

"\xEF\xBB\xBF" error (on Windows)
2 participants