OrchardCoreContrib.PoExtractor icon indicating copy to clipboard operation
OrchardCoreContrib.PoExtractor copied to clipboard

Problematic input path handling

Open skyflyer opened this issue 3 months ago • 3 comments

The current input path handling is problematic and error prone.

Steps to reproduce a problem:

  1. Create a sample project
  • mkdir SampleXX
  • cd SampleXX
  • dotnet new mvc
  • mkdir Localization
  1. 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.

skyflyer avatar Aug 10 '25 16:08 skyflyer

`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

hishamco avatar Aug 10 '25 16:08 hishamco

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...

skyflyer avatar Aug 10 '25 16:08 skyflyer

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

hishamco avatar Aug 10 '25 17:08 hishamco