Skip to content

Commit

Permalink
Merge pull request #34 from c1n1c/master
Browse files Browse the repository at this point in the history
fix: exclude \n and \t in nonprintable characters
  • Loading branch information
c1n1c authored Jun 19, 2018
2 parents d402d01 + 8f2da34 commit 361db17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/string_tools/core_ext/string.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

require 'rchardet19'
require 'addressable/uri'
require 'active_support/core_ext/module'
Expand Down Expand Up @@ -213,7 +211,7 @@ def mb_downcase
#
# Returns String
def remove_nonprintable
gsub(/[^[:print:]]/i, '')
gsub(/[^[:print:]\n\t]/i, '')
end

# Public: removes all non-printable characters from string
Expand Down
14 changes: 12 additions & 2 deletions spec/string_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

require 'spec_helper'

describe String do
Expand All @@ -11,6 +9,18 @@
let(:string) { "\uFDD1string\uFFFE \uFFFFwith\uFDEF weird characters\uFDD0" }

it { expect(string.remove_nonprintable).to eq 'string with weird characters' }

context 'when string with \n' do
let(:string) { "one\ntwo" }

it { expect(string.remove_nonprintable).to eq string }
end

context 'when string with \t' do
let(:string) { "one\ttwo" }

it { expect(string.remove_nonprintable).to eq string }
end
end

describe '#remove_nonprintable!' do
Expand Down

0 comments on commit 361db17

Please sign in to comment.