Skip to content

Commit 2a406cd

Browse files
committed
fix EvilBeaver#1580.3: исключение при лишних символах в параметре сортировки
1 parent 5e60b2c commit 2a406cd

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

src/OneScript.Language/Localization/BilingualString.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,21 @@ public static string Localize(string russian, string english)
7373

7474
return russian;
7575
}
76+
77+
public static bool BiEquals(string str, string lang1, string lang2)
78+
{
79+
StringComparison comparison = StringComparison.CurrentCultureIgnoreCase;
80+
return string.Equals(str, lang1, comparison) || string.Equals(str, lang2, comparison);
81+
}
82+
}
83+
84+
public static class BilingualStringExtension
85+
{
86+
public static bool BilingualEquals(this string str, string lang1, string lang2,
87+
StringComparison comparison = StringComparison.CurrentCultureIgnoreCase)
88+
{
89+
return string.Equals(str, lang1, comparison) || string.Equals(str, lang2, comparison);
90+
}
7691
}
92+
7793
}

src/OneScript.StandardLibrary/Collections/ValueTable/ValueTable.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This Source Code Form is subject to the terms of the
1717
using ScriptEngine.Machine;
1818
using ScriptEngine.Machine.Contexts;
1919
using OneScript.StandardLibrary.Collections.Exceptions;
20+
using OneScript.Localization;
2021

2122
namespace OneScript.StandardLibrary.Collections.ValueTable
2223
{
@@ -619,20 +620,15 @@ private List<ValueTableSortRule> GetSortRules(string Columns)
619620
string[] description = column.Trim().Split(' ');
620621
if (description.Length == 0)
621622
throw ColumnException.WrongColumnName();
622-
623-
ValueTableSortRule Desc = new ValueTableSortRule();
624-
Desc.Column = this.Columns.FindColumnByName(description[0]);
625-
626-
if (description.Length > 1)
627-
{
628-
if (String.Compare(description[1], "DESC", true) == 0 || String.Compare(description[1], "УБЫВ", true) == 0)
629-
Desc.direction = -1;
630-
else
631-
Desc.direction = 1;
632-
}
633-
else
634-
Desc.direction = 1;
635-
623+
if (description.Length > 2)
624+
throw RuntimeException.InvalidNthArgumentValue(1);
625+
626+
var Desc = new ValueTableSortRule
627+
{
628+
Column = this.Columns.FindColumnByName(description[0]),
629+
direction = (description.Length > 1 && description[1].BilingualEquals("УБЫВ", "DESC")) ? -1 : 1
630+
};
631+
636632
Rules.Add(Desc);
637633
}
638634

tests/valuetable.os

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
ВсеТесты.Добавить("ТестДолжен_ПроверитьВставкуВнеРазмераТаблицы");
5757
ВсеТесты.Добавить("ТестДолжен_ПроверитьИсключениеПриЗагрузкеКолонки");
58+
ВсеТесты.Добавить("ТестДолжен_ПроверитьИсключениеПриНеверномПараметреСортировки");
5859

5960
Возврат ВсеТесты;
6061

@@ -980,3 +981,19 @@
980981

981982
ВызватьИсключение "Ожидали исключение, но его не было";
982983
КонецПроцедуры
984+
985+
Процедура ТестДолжен_ПроверитьИсключениеПриНеверномПараметреСортировки() Экспорт
986+
ТЗ = Новый ТаблицаЗначений();
987+
ТЗ.Колонки.Добавить("Тест");
988+
ТЗ.Добавить().Тест = 1;
989+
ТЗ.Добавить().Тест = 2;
990+
991+
Попытка
992+
ТЗ.Сортировать("Тест УБЫВ и_лишнее_через_пробел");
993+
Исключение
994+
Возврат;
995+
КонецПопытки;
996+
997+
ВызватьИсключение "Ожидали исключение, но его не было";
998+
КонецПроцедуры
999+

0 commit comments

Comments
 (0)