Skip to content

Commit

Permalink
Merge pull request #131 from lacostej/fix/unicode
Browse files Browse the repository at this point in the history
Replace non unicode characters to avoid crashes
  • Loading branch information
nateberkopec authored Jan 27, 2025
2 parents 2b36467 + 93723db commit 16bc707
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/terminal-table/cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def align(val, position, length)
val.public_send(positions[position], length)
end
def lines
@value.to_s.split(/\n/)
@value.to_s.encode("utf-8", invalid: :replace).split(/\n/)
end

##
Expand Down
12 changes: 12 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ module Terminal
EOF
end

it "should replace illegal unicode characters" do
@table.headings = ["\xAE"]
@table << ['a']
@table.render.should eq <<-EOF.deindent
+---+
| � |
+---+
| a |
+---+
EOF
end

it "should render styles properly" do
@table.headings = ['Char', 'Num']
@table.style = {
Expand Down

0 comments on commit 16bc707

Please sign in to comment.