Uh oh!
There was an error while loading. Please reload this page.
Bugfix #1124 When CSDL filter and http resource supplied for HIDI input, it fails because ApplyFilter expects a local file but not a URL address - #1125
Conversation
…because ApplyFilter expects a local file but not a URL address microsoft#1124
Oleksandr Dudarenko (MazZzDaI)
commented
Jan 9, 2023
@microsoft-github-policy-service agree [company="Olk inc."] |
Oleksandr Dudarenko (MazZzDaI)
commented
Jan 9, 2023
@microsoft-github-policy-service agree company="Olk inc." |
Vincent Biret (baywet)
left a comment
There was a problem hiding this comment.
Thanks for the contribution, here are a couple of comments to help improve it
| { | ||
| XslCompiledTransform transform = GetFilterTransform(); | ||
| stream = ApplyFilter(csdl, csdlFilter, transform); | ||
| stream = csdl.StartsWith("http") ? ApplyFilter(stream, csdlFilter, transform) : ApplyFilter(csdl, csdlFilter, transform); |
There was a problem hiding this comment.
| stream=csdl.StartsWith("http")?ApplyFilter(stream,csdlFilter,transform):ApplyFilter(csdl,csdlFilter,transform); | |
| stream=csdl.StartsWith("http",StringComparison.OrdinalIgnoreCase)?ApplyFilter(newStreamReader(stream),csdlFilter,transform):ApplyFilter(newStreamReader(csdl),csdlFilter,transform); |
There was a problem hiding this comment.
The original code here seems wrong. GetStream does all the logic to determine if stream is coming from a file or via HTTP. Currently the code is getting the stream and then ignoring it if there is a filter. The solution should be to change ApplyFilter to just accept the stream that comes from GetStream. And the case-insensitive check needs to be added to GetStream.
I'm not sure why the OP closed the PR. This seems like a good thing to fix.
| private static Stream ApplyFilter(string csdl, string entitySetOrSingleton, XslCompiledTransform transform) | ||
| { | ||
| StreamReader inputReader = new(csdl); | ||
| return ApplyFilterForStreamReader(inputReader, entitySetOrSingleton, transform); | ||
| } | ||
| private static Stream ApplyFilter(Stream csdlStream, string entitySetOrSingleton, XslCompiledTransform transform) | ||
| { | ||
| StreamReader inputReader = new(csdlStream); | ||
| return ApplyFilterForStreamReader(inputReader, entitySetOrSingleton, transform); | ||
| } | ||
There was a problem hiding this comment.
| privatestaticStreamApplyFilter(stringcsdl,stringentitySetOrSingleton,XslCompiledTransformtransform) | |
| { | |
| StreamReaderinputReader=new(csdl); | |
| returnApplyFilterForStreamReader(inputReader,entitySetOrSingleton,transform); | |
| } | |
| privatestaticStreamApplyFilter(StreamcsdlStream,stringentitySetOrSingleton,XslCompiledTransformtransform) | |
| { | |
| StreamReaderinputReader=new(csdlStream); | |
| returnApplyFilterForStreamReader(inputReader,entitySetOrSingleton,transform); | |
| } |
| } | ||
| private static Stream ApplyFilter(string csdl, string entitySetOrSingleton, XslCompiledTransform transform) | ||
| private static Stream ApplyFilterForStreamReader(StreamReader inputReader, string entitySetOrSingleton, XslCompiledTransform transform) |
There was a problem hiding this comment.
| privatestaticStreamApplyFilterForStreamReader(StreamReaderinputReader,stringentitySetOrSingleton,XslCompiledTransformtransform) | |
| privatestaticStreamApplyFilter(StreamReaderinputReader,stringentitySetOrSingleton,XslCompiledTransformtransform) |
| { | ||
| StreamReader inputReader = new(csdlStream); | ||
| return ApplyFilterForStreamReader(inputReader, entitySetOrSingleton, transform); | ||
| } |
Check warning
Code scanning / CodeQL
Missing Dispose call on local IDisposable
Check warning
Code scanning / CodeQL
Missing Dispose call on local IDisposable
Vincent Biret (baywet)
commented
Jan 13, 2023
Oleksandr Dudarenko (@MazZzDaI) is there any specific reason why you closed that PR? |
Darrel (darrelmiller)
commented
Jan 15, 2023
Darrel (darrelmiller)
commented
Jan 15, 2023
Thank you Oleksandr Dudarenko (@MazZzDaI) for identifying this issue. PR #1113 has the fixes you are looking for and other related improvements. |
Fix of the #1124 issue.
Overload added for Microsoft.OpenApi.Hidi/OpenApiService.cs/ApplyFilter to accept both string and stream variables.