Skip to content

Commit

Permalink
Refactor: Revise pattern matching in uploaded file path detector. (#634)
Browse files Browse the repository at this point in the history
This patch introduces a small change, where previously the detection for
user-uploaded content paths ran multiple checks against the path for possible
directories. Now, a single `RegExp` pattern checks in a single pass if the path
refers to one of the intended directories. Performance impact should be
negligible, but why do five times what can mostly be done once.

cc: @ironprogrammer whose work in #633 prompted this change.
  • Loading branch information
dmsnell committed Sep 11, 2023
1 parent b58e396 commit 80bae72
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions packages/playground/remote/src/lib/is-uploaded-file-path.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
export const isUploadedFilePath = (path: string) => {
return (
path.startsWith('/wp-content/uploads/') ||
path.startsWith('/wp-content/plugins/') ||
path.startsWith('/wp-content/mu-plugins/') ||
path.startsWith('/wp-content/themes/') ||
path.startsWith('/wp-content/fonts/')
);
return /^wp-content\/(?:fonts|(?:mu-)?plugins|themes|uploads)\//.test(path);
};

0 comments on commit 80bae72

Please sign in to comment.