Skip to content

Commit 93723db

Browse files
committed
Replace non unicode characters to avoid crashes
1 parent 4520340 commit 93723db

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/terminal-table/cell.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def align(val, position, length)
4848
val.public_send(positions[position], length)
4949
end
5050
def lines
51-
@value.to_s.split(/\n/)
51+
@value.to_s.encode("utf-8", invalid: :replace).split(/\n/)
5252
end
5353

5454
##

spec/table_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ module Terminal
120120
EOF
121121
end
122122

123+
it "should replace illegal unicode characters" do
124+
@table.headings = ["\xAE"]
125+
@table << ['a']
126+
@table.render.should eq <<-EOF.deindent
127+
+---+
128+
| � |
129+
+---+
130+
| a |
131+
+---+
132+
EOF
133+
end
134+
123135
it "should render styles properly" do
124136
@table.headings = ['Char', 'Num']
125137
@table.style = {

0 commit comments

Comments
 (0)