diff --git a/README.md b/README.md index 067ab16..d3af18f 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ $ docker-compose ps ruby-parseconfig_parseconfig-rb26_1 /bin/bash Up ruby-parseconfig_parseconfig-rb27_1 /bin/bash Up ruby-parseconfig_parseconfig-rb30_1 /bin/bash Up +ruby-parseconfig_parseconfig-rb34_1 /bin/bash Up ruby-parseconfig_parseconfig_1 /bin/bash Up @@ -135,5 +136,3 @@ $ make test The ParseConfig library is Open Source and distributed under the MIT license. Please see the LICENSE file included with this software. - - diff --git a/docker-compose.yml b/docker-compose.yml index 8ed86cb..2f21cba 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: "3" services: parseconfig: &DEFAULTS image: "parseconfig:dev" @@ -13,20 +12,26 @@ services: - '.:/src' working_dir: '/src' + parseconfig-rb34: + <<: *DEFAULTS + image: "parseconfig:dev-rb34" + build: + context: . + dockerfile: docker/Dockerfile.dev-rb34 parseconfig-rb30: <<: *DEFAULTS image: "parseconfig:dev-rb30" build: context: . dockerfile: docker/Dockerfile.dev-rb30 - + parseconfig-rb27: <<: *DEFAULTS image: "parseconfig:dev-rb27" build: context: . dockerfile: docker/Dockerfile.dev-rb27 - + parseconfig-rb26: <<: *DEFAULTS image: "parseconfig:dev-rb26" diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 0194a82..c455739 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM ruby:3.0-alpine +FROM ruby:3.4-alpine LABEL MAINTAINER="BJ Dierkes " ENV PS1="\[\e[0;33m\]|> parseconfig <| \[\e[1;35m\]\W\[\e[0m\] \[\e[0m\]# " diff --git a/docker/Dockerfile.dev-rb30 b/docker/Dockerfile.dev-rb30 index 10b0ba0..5066f33 100644 --- a/docker/Dockerfile.dev-rb30 +++ b/docker/Dockerfile.dev-rb30 @@ -1,6 +1,6 @@ FROM ruby:3.0-alpine LABEL MAINTAINER="BJ Dierkes " -ENV PS1="\[\e[0;33m\]|> parseconfig-rb28 <| \[\e[1;35m\]\W\[\e[0m\] \[\e[0m\]# " +ENV PS1="\[\e[0;33m\]|> parseconfig-rb30 <| \[\e[1;35m\]\W\[\e[0m\] \[\e[0m\]# " WORKDIR /src RUN apk update \ diff --git a/docker/Dockerfile.dev-rb34 b/docker/Dockerfile.dev-rb34 new file mode 100644 index 0000000..0b72515 --- /dev/null +++ b/docker/Dockerfile.dev-rb34 @@ -0,0 +1,16 @@ +FROM ruby:3.4-alpine +LABEL MAINTAINER="BJ Dierkes " +ENV PS1="\[\e[0;33m\]|> parseconfig-rb34 <| \[\e[1;35m\]\W\[\e[0m\] \[\e[0m\]# " + +WORKDIR /src +RUN apk update \ + && apk add \ + musl-dev \ + make \ + vim \ + bash \ + && ln -sf /usr/bin/vim /usr/bin/vi \ + && gem install rspec +COPY . /src +COPY docker/vimrc /root/.vimrc +CMD ["/bin/bash"] diff --git a/lib/parseconfig.rb b/lib/parseconfig.rb index e4047c0..271fda3 100644 --- a/lib/parseconfig.rb +++ b/lib/parseconfig.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Author:: BJ Dierkes # Copyright:: Copyright (c) 2006,2016 Data Folk Labs, LLC @@ -29,7 +31,7 @@ def initialize(config_file = nil, separator = '=', comments = ['#', ';']) @config_file = config_file @params = {} @groups = [] - @split_regex = '\s*' + separator + '\s*' + @split_regex = /\s*#{Regexp.escape(separator)}\s*/ @comments = comments return unless config_file @@ -56,12 +58,13 @@ def import_config f.each_with_index do |line, i| line.strip! - # force_encoding not available in all versions of ruby - begin - if i.eql? 0 && line.include?("\xef\xbb\xbf".force_encoding('UTF-8')) - line.delete!("\xef\xbb\xbf".force_encoding('UTF-8')) + if i.eql? 0 + # force_encoding not available in all versions of ruby + begin + bom = (+"\xef\xbb\xbf").force_encoding('UTF-8') + line.delete!(bom) if line.include?(bom) + rescue NoMethodError end - rescue NoMethodError end is_comment = false @@ -73,8 +76,8 @@ def import_config end unless is_comment - if /#{@split_regex}/.match(line) - param, value = line.split(/#{@split_regex}/, 2) + if @split_regex.match(line) + param, value = line.split(@split_regex, 2) var_name = param.to_s.chomp.strip value = value.chomp.strip new_value = ''