mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Warn when :newline precedes other newline options
This commit is contained in:
parent
8bb24712de
commit
eb737916b1
2 changed files with 13 additions and 4 deletions
|
@ -922,7 +922,9 @@ class TestEncodingConverter < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
newlines.each do |nl|
|
newlines.each do |nl|
|
||||||
opts = {newline: :universal, nl => true}
|
opts = {newline: :universal, nl => true}
|
||||||
ec2 = Encoding::Converter.new("", "", **opts)
|
ec2 = assert_warning(/:newline option preceds/, opts.inspect) do
|
||||||
|
Encoding::Converter.new("", "", **opts)
|
||||||
|
end
|
||||||
assert_equal(ec1, ec2)
|
assert_equal(ec1, ec2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
13
transcode.c
13
transcode.c
|
@ -2418,6 +2418,7 @@ static int
|
||||||
econv_opts(VALUE opt, int ecflags)
|
econv_opts(VALUE opt, int ecflags)
|
||||||
{
|
{
|
||||||
VALUE v;
|
VALUE v;
|
||||||
|
int newlineflag = 0;
|
||||||
|
|
||||||
v = rb_hash_aref(opt, sym_invalid);
|
v = rb_hash_aref(opt, sym_invalid);
|
||||||
if (NIL_P(v)) {
|
if (NIL_P(v)) {
|
||||||
|
@ -2463,6 +2464,7 @@ econv_opts(VALUE opt, int ecflags)
|
||||||
#ifdef ENABLE_ECONV_NEWLINE_OPTION
|
#ifdef ENABLE_ECONV_NEWLINE_OPTION
|
||||||
v = rb_hash_aref(opt, sym_newline);
|
v = rb_hash_aref(opt, sym_newline);
|
||||||
if (!NIL_P(v)) {
|
if (!NIL_P(v)) {
|
||||||
|
newlineflag = 2;
|
||||||
ecflags &= ~ECONV_NEWLINE_DECORATOR_MASK;
|
ecflags &= ~ECONV_NEWLINE_DECORATOR_MASK;
|
||||||
if (v == sym_universal) {
|
if (v == sym_universal) {
|
||||||
ecflags |= ECONV_UNIVERSAL_NEWLINE_DECORATOR;
|
ecflags |= ECONV_UNIVERSAL_NEWLINE_DECORATOR;
|
||||||
|
@ -2484,10 +2486,9 @@ econv_opts(VALUE opt, int ecflags)
|
||||||
rb_raise(rb_eArgError, "unexpected value for newline option");
|
rb_raise(rb_eArgError, "unexpected value for newline option");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
int setflags = 0, newlineflag = 0;
|
int setflags = 0;
|
||||||
|
|
||||||
v = rb_hash_aref(opt, sym_universal_newline);
|
v = rb_hash_aref(opt, sym_universal_newline);
|
||||||
if (RTEST(v))
|
if (RTEST(v))
|
||||||
|
@ -2504,9 +2505,15 @@ econv_opts(VALUE opt, int ecflags)
|
||||||
setflags |= ECONV_CR_NEWLINE_DECORATOR;
|
setflags |= ECONV_CR_NEWLINE_DECORATOR;
|
||||||
newlineflag |= !NIL_P(v);
|
newlineflag |= !NIL_P(v);
|
||||||
|
|
||||||
if (newlineflag) {
|
switch (newlineflag) {
|
||||||
|
case 1:
|
||||||
ecflags &= ~ECONV_NEWLINE_DECORATOR_MASK;
|
ecflags &= ~ECONV_NEWLINE_DECORATOR_MASK;
|
||||||
ecflags |= setflags;
|
ecflags |= setflags;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
rb_warning(":newline option preceds other newline options");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue