-
Notifications
You must be signed in to change notification settings - Fork 34
Stricter filename validations #2374
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,276 @@ public async Task CreatesDefaultOutputDirectory() | |
| await collector.StopAsync(TestContext.Current.CancellationToken); | ||
|
|
||
| fileSystem.Directory.Exists(".artifacts").Should().BeTrue(); | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(ValidFileNames))] | ||
| public void OutputFileValidationValidNames(string fileName) | ||
| { | ||
| var valid = DocumentationGenerator.IsValidFileName(fileName); | ||
| valid.Should().BeTrue($"'{fileName}' should be a valid filename"); | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(InvalidFileNames))] | ||
| public void OutputFileValidationInvalidNames(string fileName) | ||
| { | ||
| var valid = DocumentationGenerator.IsValidFileName(fileName); | ||
| valid.Should().BeFalse($"'{fileName}' should be an invalid filename"); | ||
| } | ||
|
|
||
| public static TheoryData<string> ValidFileNames => | ||
| [ | ||
| "test.md", | ||
| "file.txt", | ||
| "index.html", | ||
| "readme.rst", | ||
|
|
||
| // With numbers | ||
| "test123.md", | ||
| "123test.md", | ||
| "file2.md", | ||
| "99bottles.md", | ||
|
|
||
| // With underscores | ||
| "test_file.md", | ||
| "my_long_file_name.md", | ||
| "_leading_underscore.md", | ||
| "trailing_underscore_.md", | ||
|
|
||
| // With hyphens | ||
| "test-file.md", | ||
| "my-long-file-name.md", | ||
| "trailing-hyphen-.md", | ||
|
|
||
| // Combined underscores and hyphens | ||
| "test_file-name.md", | ||
| "my-file_name.md", | ||
|
|
||
| // With dots in filename (before extension) | ||
| "test.config.md", | ||
| "file.test.backup.md", | ||
| "v1.0.0.md", | ||
|
|
||
| // With spaces (allowed per regex) | ||
| "test file.md", | ||
| "my document.md", | ||
|
|
||
| // Paths with all lowercase directories | ||
| "path/to/file.md", | ||
| "deep/nested/path/to/file.md", | ||
| "folder/subfolder/document.md", | ||
|
|
||
| // Paths with numbers | ||
| "path123/file.md", | ||
| "v1/docs/guide.md", | ||
|
|
||
| // Paths with underscores and hyphens | ||
| "my_folder/file.md", | ||
| "my-folder/file.md", | ||
| "path_to/sub-folder/file.md", | ||
|
|
||
| // SVG files exception (even with uppercase - per the .EndsWith checks) | ||
| "image.svg", | ||
| "Icon.svg", | ||
| "LOGO.svg", | ||
| "path/to/Image.svg", | ||
|
|
||
| // PNG files exception | ||
| "image.png", | ||
| "Screenshot.png", | ||
| "IMAGE.png", | ||
| "path/to/Logo.png", | ||
|
|
||
| // GIF files exception | ||
| "animation.gif", | ||
| "Loading.gif", | ||
| "SPINNER.gif", | ||
|
|
||
| // ESQL snippets exception (prior art) | ||
| "reference/query-languages/esql/_snippets/functions/examples/cbrt.md", | ||
| "reference/query-languages/esql/_snippets/anything/here/File.md", | ||
| "reference/query-languages/esql/_snippets/UPPERCASE.md", | ||
|
|
||
| // Hardcoded exceptions | ||
| "reference/security/prebuilt-rules/audit_policies/windows/README.md", | ||
| "extend/integrations/developer-workflow-fleet-UI.md", | ||
| "reference/elasticsearch/clients/ruby/Helpers.md", | ||
| "explore-analyze/ai-features/llm-guides/connect-to-vLLM.md" | ||
| ]; | ||
|
|
||
| public static TheoryData<string> InvalidFileNames => | ||
| [ | ||
| "Test.md", | ||
| "FILE.md", | ||
| "MyFile.md", | ||
| "testFile.md", | ||
| "README.md", | ||
|
|
||
| // Uppercase in extension | ||
| "test.MD", | ||
| "test.Md", | ||
| "file.TXT", | ||
| "document.Html", | ||
|
|
||
| // Uppercase in directory path | ||
| "Path/file.md", | ||
| "path/To/file.md", | ||
| "FOLDER/file.md", | ||
| "docs/MyFolder/file.md", | ||
|
|
||
| // Filenames starting with invalid characters (must start with [a-z0-9_]) | ||
| "-leading-hyphen.md", | ||
| "-file.md", | ||
| ".hidden.md", | ||
| " leading-space.md", | ||
| "path/to/-invalid.md", | ||
| "path/to/.hidden.md", | ||
| "path/to/ space.md", | ||
|
|
||
| // Special characters - parentheses | ||
| "test(1).md", | ||
| "file (copy).md", | ||
| "document(v2).md", | ||
|
|
||
| // Special characters - square brackets | ||
| "test[1].md", | ||
| "file[copy].md", | ||
|
|
||
| // Special characters - curly braces | ||
| "test{1}.md", | ||
|
|
||
| // Special characters - exclamation mark | ||
| "test!.md", | ||
| "important!file.md", | ||
|
|
||
| // Special characters - at sign | ||
| "[email protected]", | ||
| "[email protected]", | ||
|
|
||
| // Special characters - hash | ||
| "test#1.md", | ||
| "file#.md", | ||
|
|
||
| // Special characters - dollar sign | ||
| "test$file.md", | ||
| "price$.md", | ||
|
|
||
| // Special characters - percent | ||
| "test%file.md", | ||
| "100%done.md", | ||
|
|
||
| // Special characters - caret | ||
| "test^file.md", | ||
|
|
||
| // Special characters - ampersand | ||
| "test&file.md", | ||
| "this&that.md", | ||
|
|
||
| // Special characters - asterisk | ||
| "test*file.md", | ||
| "*.md", | ||
|
|
||
| // Special characters - plus sign | ||
| "test+file.md", | ||
| "c++.md", | ||
|
|
||
| // Special characters - equals sign | ||
| "test=file.md", | ||
|
|
||
| // Special characters - pipe | ||
| "test|file.md", | ||
|
|
||
| // Special characters - less than / greater than | ||
| "test<file>.md", | ||
|
|
||
| // Special characters - colon | ||
| "test:file.md", | ||
|
|
||
| // Special characters - semicolon | ||
| "test;file.md", | ||
|
|
||
| // Special characters - single quote | ||
| "test'file.md", | ||
| "it's.md", | ||
|
|
||
| // Special characters - double quote | ||
| "test\"file.md", | ||
|
|
||
| // Special characters - backtick | ||
| "test`file.md", | ||
|
|
||
| // Special characters - tilde | ||
| "test~file.md", | ||
| "~temp.md", | ||
|
|
||
| // Special characters - comma | ||
| "test,file.md", | ||
| "a,b,c.md", | ||
|
|
||
| // Special characters - question mark | ||
| "test?.md", | ||
| "what?.md", | ||
|
|
||
| // No extension | ||
| "testfile", | ||
| "README", | ||
| "Makefile", | ||
|
|
||
| // Just extension | ||
| ".md", | ||
| ".txt", | ||
|
|
||
| // Empty extension | ||
| "test.", | ||
|
|
||
| // Double extension edge cases with uppercase | ||
| "test.Config.md", | ||
| "file.Test.md", | ||
|
|
||
| // Non-ASCII characters - accented | ||
| "tëst.md", | ||
| "café.md", | ||
| "naïve.md", | ||
| "résumé.md", | ||
|
|
||
| // Non-ASCII characters - other alphabets | ||
| "тест.md", | ||
| "测试.md", | ||
| "テスト.md", | ||
|
|
||
| // Non-ASCII characters - symbols | ||
| "test™.md", | ||
| "file©.md", | ||
|
|
||
| // Empty string | ||
| "", | ||
|
|
||
| // Whitespace only | ||
| " ", | ||
|
|
||
| // Extension only variations | ||
| "..md", | ||
|
|
||
| // Numbers in extension (if we expect only letters) | ||
| "test.md5", | ||
| "file.mp3", | ||
| "video.mp4", | ||
|
|
||
| // CamelCase variations | ||
| "camelCase.md", | ||
| "PascalCase.md", | ||
| "mixedCASE.md", | ||
|
|
||
| // Acronyms | ||
| "API.md", | ||
| "HTTP.md", | ||
| "XMLParser.md", | ||
|
|
||
| // Common problematic filenames | ||
| "CHANGELOG.md", | ||
| "LICENSE.md", | ||
| "CONTRIBUTING.md", | ||
| "TODO.md" | ||
| ]; | ||
| } | ||
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.
Not sure if directly related to this change, but docs builds in the integrations repository are failing since around the time it was merged. With the following error:
First failed build is this one: https://github.com/elastic/integrations/actions/runs/20336771987/job/58425304911
Should this path be modified like this?
cc @elastic/ecosystem @elastic/docs-engineering
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.
Thanks for pointing this out @jsoriano !
I validated the global site build (which uses prefixed paths) but isolated builds (on PR's) use the local paths. Included both now as per:
#2410
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.
Thanks!