-
Notifications
You must be signed in to change notification settings - Fork 115
Strip null characters from file paths to fix Windows WebDAV compatibility #1649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+149
−0
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a3ab2d1
Initial plan
Copilot 99424c1
Initial plan for fixing null character handling in file paths
Copilot e80ffba
Add null character stripping in FileContext and FindFiles
Copilot ed9d9b7
Refactor: Extract StripNullCharacters to PathHelper utility class
Copilot 24302b9
Final update: All checks passed
Copilot bdba29f
Remove accidentally committed opm.ospx file
Copilot 5fe9338
Remove nuget.exe and C# test file (BSL tests are sufficient)
Copilot 81510f3
Strip null characters from file paths to fix Windows WebDAV compatibi…
Copilot e61629b
Revert .gitignore change - remove *.ospx pattern
Copilot 0c231ed
Remove accidentally re-added opm.ospx file
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /*---------------------------------------------------------- | ||
| This Source Code Form is subject to the terms of the | ||
| Mozilla Public License, v.2.0. If a copy of the MPL | ||
| was not distributed with this file, You can obtain one | ||
| at http://mozilla.org/MPL/2.0/. | ||
| ----------------------------------------------------------*/ | ||
|
|
||
| namespace OneScript.StandardLibrary | ||
| { | ||
| /// <summary> | ||
| /// Utility methods for working with file paths | ||
| /// </summary> | ||
| internal static class PathHelper | ||
| { | ||
| /// <summary> | ||
| /// Strips null characters from a path string. | ||
| /// This is needed because Windows WebDAV client can add null characters to paths, | ||
| /// which causes ArgumentException in System.IO methods. | ||
| /// </summary> | ||
| /// <param name="path">Path that may contain null characters</param> | ||
| /// <returns>Path with null characters removed, or null if input was null</returns> | ||
| public static string StripNullCharacters(string path) | ||
| { | ||
| if (path == null) | ||
| return null; | ||
|
|
||
| return path.Replace("\0", ""); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| Перем юТест; | ||
|
|
||
| Функция Версия() Экспорт | ||
| Возврат "0.1"; | ||
| КонецФункции | ||
|
|
||
| Функция ПолучитьСписокТестов(ЮнитТестирование) Экспорт | ||
|
|
||
| юТест = ЮнитТестирование; | ||
|
|
||
| ВсеТесты = Новый Массив; | ||
|
|
||
| ВсеТесты.Добавить("ТестДолжен_СоздатьФайлСНулевымСимволом"); | ||
| ВсеТесты.Добавить("ТестДолжен_ВыполнитьНайтиФайлыСНулевымСимволом"); | ||
| ВсеТесты.Добавить("ТестДолжен_ПолучитьСвойстваФайлаСНулевымСимволом"); | ||
|
|
||
| Возврат ВсеТесты; | ||
| КонецФункции | ||
|
|
||
| Процедура ТестДолжен_СоздатьФайлСНулевымСимволом() Экспорт | ||
|
|
||
| ВремФайл = ПолучитьИмяВременногоФайла("txt"); | ||
| ЗаписьТекста = Новый ЗаписьТекста(ВремФайл); | ||
| ЗаписьТекста.ЗаписатьСтроку("тестовое содержимое"); | ||
| ЗаписьТекста.Закрыть(); | ||
|
|
||
| Попытка | ||
| // Добавляем нулевой символ в путь, как это делает Windows WebDAV клиент | ||
| ПутьСНулевымСимволом = ВремФайл + Символ(0); | ||
| Файл = Новый Файл(ПутьСНулевымСимволом); | ||
|
|
||
| // Проверяем, что файл доступен и не выбрасывает исключение | ||
| юТест.ПроверитьИстину(Файл.Существует(), "Файл должен существовать"); | ||
| юТест.ПроверитьРавенство("txt", Прав(Файл.Расширение, 3), "Расширение должно быть txt"); | ||
|
|
||
| Исключение | ||
| УдалитьФайлы(ВремФайл); | ||
| ВызватьИсключение; | ||
| КонецПопытки; | ||
|
|
||
| УдалитьФайлы(ВремФайл); | ||
|
|
||
| КонецПроцедуры | ||
|
|
||
| Процедура ТестДолжен_ВыполнитьНайтиФайлыСНулевымСимволом() Экспорт | ||
|
|
||
| ВремКаталог = КаталогВременныхФайлов(); | ||
| ИмяТестовогоФайла = "test_null_char_" + Формат(ТекущаяДата(), "ДФ=yyyyMMddHHmmss") + ".txt"; | ||
| ВремФайл = ОбъединитьПути(ВремКаталог, ИмяТестовогоФайла); | ||
|
|
||
| ЗаписьТекста = Новый ЗаписьТекста(ВремФайл); | ||
| ЗаписьТекста.ЗаписатьСтроку("тестовое содержимое"); | ||
| ЗаписьТекста.Закрыть(); | ||
|
|
||
| Попытка | ||
| // Добавляем нулевой символ в путь к каталогу | ||
| ПутьКаталогаСНулевымСимволом = ВремКаталог + Символ(0); | ||
|
|
||
| // Проверяем, что НайтиФайлы не выбрасывает исключение | ||
| НайденныеФайлы = НайтиФайлы(ПутьКаталогаСНулевымСимволом, ИмяТестовогоФайла); | ||
|
|
||
| // Проверяем, что файл был найден | ||
| юТест.ПроверитьРавенство(1, НайденныеФайлы.Количество(), "Должен быть найден один файл"); | ||
| юТест.ПроверитьРавенство(ИмяТестовогоФайла, НайденныеФайлы[0].Имя, "Имя файла должно совпадать"); | ||
|
|
||
| Исключение | ||
| УдалитьФайлы(ВремФайл); | ||
| ВызватьИсключение; | ||
| КонецПопытки; | ||
|
|
||
| УдалитьФайлы(ВремФайл); | ||
|
|
||
| КонецПроцедуры | ||
|
|
||
| Процедура ТестДолжен_ПолучитьСвойстваФайлаСНулевымСимволом() Экспорт | ||
|
|
||
| ВремФайл = ПолучитьИмяВременногоФайла("txt"); | ||
| ЗаписьТекста = Новый ЗаписьТекста(ВремФайл); | ||
| ЗаписьТекста.ЗаписатьСтроку("тестовое содержимое"); | ||
| ЗаписьТекста.Закрыть(); | ||
|
|
||
| Попытка | ||
| // Добавляем нулевой символ в конец пути | ||
| ПутьСНулевымСимволом = ВремФайл + Символ(0); | ||
| Файл = Новый Файл(ПутьСНулевымСимволом); | ||
|
|
||
| // Проверяем, что все свойства доступны без исключений | ||
| ПолноеИмя = Файл.ПолноеИмя; | ||
| юТест.ПроверитьНеравенство("", ПолноеИмя, "ПолноеИмя не должно быть пустым"); | ||
|
|
||
| Имя = Файл.Имя; | ||
| юТест.ПроверитьНеравенство("", Имя, "Имя не должно быть пустым"); | ||
|
|
||
| Путь = Файл.Путь; | ||
| юТест.ПроверитьНеравенство("", Путь, "Путь не должен быть пустым"); | ||
|
|
||
| Расширение = Файл.Расширение; | ||
| юТест.ПроверитьРавенство(".txt", Расширение, "Расширение должно быть .txt"); | ||
|
|
||
| Размер = Файл.Размер(); | ||
| юТест.ПроверитьБольше(Размер, 0, "Размер должен быть больше 0"); | ||
|
|
||
| Исключение | ||
| УдалитьФайлы(ВремФайл); | ||
| ВызватьИсключение; | ||
| КонецПопытки; | ||
|
|
||
| УдалитьФайлы(ВремФайл); | ||
|
|
||
| КонецПроцедуры |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут бы конечно русскоязычный док, но не будем докапываться, все кто будет код смотреть, понимают, что тут написано.