mdanish98 opened a new issue, #1264:
URL: https://github.com/apache/poi/issues/1264

   Hey folks, ran into a bug in `PackagingURIHelper.getRelationshipPartName()` 
that silently returns `null` when the input part name contains percent-encoded 
characters like `%20` for spaces.
   
   ## What's happening
   
   The method calls `partName.getURI().getPath()` which decodes 
percent-encoding — so `/aasx/test%20document.txt` becomes `/aasx/test 
document.txt`. That decoded string then gets passed to `createPartName()`, 
which internally calls `new URI(fullPath)`. Since literal spaces are illegal in 
URIs, it throws `URISyntaxException`, which gets caught and silently swallowed 
with a `return null`.
   
   The comment even says "Should never happen in production" — but it 
absolutely does happen whenever filenames contain spaces or other characters 
requiring percent-encoding.
   
   ## Affected code
   
   `org.apache.poi.openxml4j.opc.PackagingURIHelper.getRelationshipPartName()`
   
   ```java
   String fullPath = partName.getURI().getPath();  // BUG: decodes %20 to space
   // ... path manipulation ...
   retPartName = createPartName(fullPath);  // FAILS: space is illegal in URI
   ```
   
   ## Steps to reproduce
   
   1. Create an OPC package (`.aasx`, `.docx`, `.xlsx`, `.pptx`) with a part 
that has spaces in its filename, e.g. stored internally as 
`/aasx/test%20text%20document.txt`
   2. Open it with POI and try to resolve relationships for that part
   3. `getRelationshipPartName()` returns `null`
   
   ## Suggested fix
   
   Replace `getPath()` with `getRawPath()` to preserve percent-encoding:
   
   ```java
   // Before (buggy):
   String fullPath = partName.getURI().getPath();
   
   // After (fixed):
   String fullPath = partName.getURI().getRawPath();
   ```
   
   The comparison at the top of the method also uses `getPath()` on both sides 
— it works by coincidence since both sides are decoded consistently, but should 
also be updated to `getRawPath()` for correctness.
   
   ## Context
   
   Hit this while working on 
[eclipse-aas4j](https://github.com/eclipse-aas4j/aas4j) where AASX packages 
with embedded files containing spaces in their names caused relationship 
resolution to fail silently. The fix is minimal — just swapping `getPath()` for 
`getRawPath()`. Happy to submit a patch if this looks good to you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to