diff --git a/.changelog_entries/6123d01cfe6b33654e12794527ec5118.json b/.changelog_entries/6123d01cfe6b33654e12794527ec5118.json
new file mode 100644
index 0000000..292607d
--- /dev/null
+++ b/.changelog_entries/6123d01cfe6b33654e12794527ec5118.json
@@ -0,0 +1 @@
+{"type":"Fixed","tickets":[],"description":"Corrected bug where the ends of escape sequences were not being correctly detected","tags":["bug"]}
\ No newline at end of file
diff --git a/spec/oho/converter_spec.cr b/spec/oho/converter_spec.cr
index a91e1e4..f9c0e85 100644
--- a/spec/oho/converter_spec.cr
+++ b/spec/oho/converter_spec.cr
@@ -4,22 +4,22 @@ describe Oho::Converter do
# TODO: Write tests
default_options = {:background_color => "white",
:foreground_color => "black"}
- # it "creates inline styles" do
- # c = Oho::Converter.new(default_options)
- # # STDERR.puts("\\033[31mhi\\033[0m")
- # test_string = "\033[31mhi\033[0m"
- # response, escape_code = c.process(test_string, nil)
- # # c.process(test_string).should(eq("hi"))
- # response.should(eq("hi"))
- #
- # end
- #
- # it "handles escape codes that terminate on subsequent lines" do
- # c = Oho::Converter.new(default_options)
- # test_string = "\033[36mfoo\nbar\033[0m baz"
- # response, escape_code = c.process(test_string, nil)
- # response.should(eq("foo\n
bar baz"))
- # end
+ it "creates inline styles" do
+ c = Oho::Converter.new(default_options)
+ # STDERR.puts("\\033[31mhi\\033[0m")
+ test_string = "\033[31mhi\033[0m"
+ response, escape_code = c.process(test_string, nil)
+ # c.process(test_string).should(eq("hi"))
+ response.should(eq("hi"))
+
+ end
+
+ it "handles escape codes that terminate on subsequent lines" do
+ c = Oho::Converter.new(default_options)
+ test_string = "\033[36mfoo\nbar\033[0m baz"
+ response, escape_code = c.process(test_string, nil)
+ response.should(eq("foo\n
bar baz"))
+ end
describe "#extract_next_escape_code" do
# there are too damn many options to do a unit test for each one
# looping over grouped arrays of them to make sure all are tested
@@ -34,6 +34,15 @@ describe Oho::Converter do
code.class.should(eq(Oho::ColorEscapeCode))
end
end
+ it "stops at end of escape code" do
+ # test_string = "\033[31mhi\033[0m"
+ reader = Char::Reader.new("[31mhi\033[0m")
+ code, reader = c.extract_next_escape_code('[', reader)
+ reader.has_next?().should(eq(true))
+ reader.next_char.should(eq('h'))
+ code.as(Oho::EscapeCode).to_span(nil).should(eq(""))
+
+ end
it "returs ColorEscapeCode for color codes" do
seqs = [
"[m", # same as 0n
diff --git a/src/oho/converter.cr b/src/oho/converter.cr
index 900c074..7de2dd1 100644
--- a/src/oho/converter.cr
+++ b/src/oho/converter.cr
@@ -167,11 +167,12 @@ module Oho
if first_char == '['
zero_val_enders = ['H', 'f', 's', 'u', 'K']
- val_enders = ['A', 'B', 'C', 'D', 's', 'h', 'l', 'p']
- if seq_length = 2
+ val_enders = ['A', 'B', 'C', 'D', 's', 'h', 'l', 'p', 'm']
+ if seq_length == 2
return true if zero_val_enders.includes? current_char
elsif seq_length == 3
- return true if current_char == 'j' # assuming prior was '2'
+ return true if ['j', 'm'].includes? current_char
+ # if j assuming prior was '2'
else # must be > 3
return true if val_enders.includes? current_char
end