Skip to content

Use platform-aware path separator in WpressValidator - #830

Merged
fredrikekelund merged 2 commits into
trunkfrom
f26d/wpress-windows-path-separators
Jan 23, 2025
Merged

Use platform-aware path separator in WpressValidator#830
fredrikekelund merged 2 commits into
trunkfrom
f26d/wpress-windows-path-separators

Conversation

@fredrikekelund

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

BackupHandlerWpress::listFiles uses path.join when enumerating the files in a .wpress archive (All-in-One WP Migration format). This breaks WpressValidator on Windows because it assumes Unix style path separators in both canHandle and parseBackupContents.

This PR fixes the problem by replacing '/' with path.sep and by changing the unit tests to account for both Unix and Windows-style paths.

Testing Instructions

  1. Import a .wpress archive on Windows
  2. Ensure that the import completes successfully and the site works

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@fredrikekelund
fredrikekelund requested a review from a team January 22, 2025 12:34
@fredrikekelund fredrikekelund self-assigned this Jan 22, 2025
return (
requiredFiles.every( ( file ) => fileList.includes( file ) ) &&
fileList.some( ( file ) => optionalDirs.some( ( dir ) => file.startsWith( dir + '/' ) ) )
optionalDirs.some( ( dir ) => fileList.some( ( file ) => file.startsWith( dir + path.sep ) ) )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from '/' to path.sep is the only functional change here. I flipped the order of fileList.some and optionalDirs.some because I find it easier to read this way.

@wojtekn wojtekn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks clear. Importing .wpress fikle works fine on Windows now. Good catch!

@fredrikekelund
fredrikekelund merged commit 94031d3 into trunk Jan 23, 2025
@fredrikekelund
fredrikekelund deleted the f26d/wpress-windows-path-separators branch January 23, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants