Skip to content

Commit

Permalink
[fastlane_core] fix the display of non-unicode characters when printi…
Browse files Browse the repository at this point in the history
…ng lane context (#21857)

* [fix] Do not crash when non unicode characters are sent to print

* Also test when verbose is on

* Move fix into terminal-table gem, and monkey patch it until a new gem ie released
  • Loading branch information
lacostej committed Feb 17, 2024
1 parent c18d01c commit 8c4903c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
36 changes: 36 additions & 0 deletions fastlane/spec/lane_manager_base_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
describe Fastlane do
describe Fastlane::LaneManagerBase do
describe "#print_lane_context" do
it "prints lane context" do
Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::LANE_NAME] = "test"

cleaned_row_data = [[:LANE_NAME, "test"]]

table_data = FastlaneCore::PrintTable.transform_output(cleaned_row_data)
expect(FastlaneCore::PrintTable).to receive(:transform_output).with(cleaned_row_data).and_call_original
expect(Terminal::Table).to receive(:new).with({
title: "Lane Context".yellow,
rows: table_data
})
Fastlane::LaneManagerBase.print_lane_context
end

it "prints lane context" do
Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::LANE_NAME] = "test"

expect(UI).to receive(:important).with('Lane Context:'.yellow)
expect(UI).to receive(:message).with(Fastlane::Actions.lane_context)

FastlaneSpec::Env.with_verbose(true) do
Fastlane::LaneManagerBase.print_lane_context
end
end

it "doesn't crash when lane_context contains non unicode text" do
Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::LANE_NAME] = "test\xAE"

Fastlane::LaneManagerBase.print_lane_context
end
end
end
end
16 changes: 16 additions & 0 deletions fastlane_core/lib/fastlane_core/print_table.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
require_relative 'configuration/configuration'
require_relative 'helper'

# Monkey patch Terminal::Table until this is merged
# https://github.com/tj/terminal-table/pull/131
# solves https://github.com/fastlane/fastlane/issues/21852
# loads Terminal::Table first to be able to monkey patch it.
require 'terminal-table'
module Terminal
class Table
class Cell
def lines
# @value.to_s.split(/\n/)
@value.to_s.encode("utf-8", invalid: :replace).split(/\n/)
end
end
end
end

module FastlaneCore
class PrintTable
class << self
Expand Down

0 comments on commit 8c4903c

Please sign in to comment.