OrchardCoreContrib.PoExtractor
OrchardCoreContrib.PoExtractor copied to clipboard
Problematic input path handling
The current input path handling is problematic and error prone.
Steps to reproduce a problem:
- Create a sample project
mkdir SampleXXcd SampleXXdotnet new mvcmkdir Localization
- Try to invoke the program with the path of the project and localization path:
- `dotnet run -- path/to/SampleXX/ path/to/SampleXX/Localization
Expected outcome
Found 0 strings
Actual outcome
Unhandled exception. System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex')
at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)
at System.String.Substring(Int32 startIndex, Int32 length)
at OrchardCoreContrib.PoExtractor.Program.<>c__DisplayClass0_0.<<Main>b__3>d.MoveNext()
Analysis
The input path logic with project base and rooted projects is fragile and should be rethought in the context of how this tool is to be used. I guess it works for Orchard CMS as it is used today, but is fragile if used on other projects.
The simple workaround is to not include the trailing directory separator (/) in the first argument.
I also believe it not a best practice that ignored projects is populated with the predefined strings and that the ignored projects should be rather renamed to ignored paths that will not be searched for the C# projects and/or template files.
`dotnet run -- path/to/SampleXX/ path/to/SampleXX/Localization
Are you on Linux?
IMHO, we need more unit tests to validate the inputs. Please propose a PR that fixes the issue, a unit or functional test will be useful
Thanks
Are you on Linux?
No, macOS.
IMHO, we need more unit tests to validate the inputs. Please propose a PR that fixes the issue, a unit or functional test will be useful
I agree. In order to prepare that, I need a bit of context - some instructions how this extractor is used in OrchardCore. Saying that it is used for "OrchardCore.Translations" does not help a lot, as the (Orchard CMS) project structure is quite convoluted and it is super time-consuming to investigate how the extractpo is supposed to be used on the codebase.
A simple guidance in terms of "extractpo Path/To/OrchardCoreRepo..." would suffice, so that I check if the change breaks something...
I will review the tool tonight, and I will check if there are proper unit tests; otherwise, I might need to add some to make sure nothing breaks if there's a change