Skip to content

Commit cb9fca4

Browse files
committed
fix #7165, leave more tabs alone in triple-quoted strings
1 parent 6a07ad5 commit cb9fca4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

base/string.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ function indentation(s::String)
963963
end
964964

965965
function unindent(s::String, indent::Int)
966+
indent == 0 && return s
966967
buf = IOBuffer(Array(Uint8,endof(s)), true, true)
967968
truncate(buf,0)
968969
a = i = start(s)
@@ -973,7 +974,9 @@ function unindent(s::String, indent::Int)
973974
if cutting && isblank(c)
974975
a = i_
975976
cut += blank_width(c)
976-
if cut > indent
977+
if cut == indent
978+
cutting = false
979+
elseif cut > indent
977980
cutting = false
978981
for _ = (indent+1):cut write(buf, ' ') end
979982
end

test/strings.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,23 @@ s = " p"
806806
@test """
807807
$s
808808
""" == " $s$(nl)"
809+
@test """\t""" == "\t"
810+
@test """
811+
\t""" == ""
812+
@test """
813+
foo
814+
\tbar""" == "foo\n\tbar"
815+
@test """
816+
foo
817+
\tbar
818+
""" == "foo\n\tbar\n"
819+
@test """
820+
foo
821+
bar\t""" == "foo\nbar\t"
822+
@test """
823+
foo
824+
\tbar
825+
""" == "foo\n bar\n"
809826

810827
# bytes2hex and hex2bytes
811828
hex_str = "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"

0 commit comments

Comments
 (0)