Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
.gitattributes
.gitignore
.idea
.lando.yml
.wp-env.override.json
.wordpress.org
bin
tests
codeception.dist.yml
composer.json
composer.lock
package.json
package-lock.json
.wp-env.json
grumphp.yml
phpcs.ruleset.xml
phpcs.xml
Expand Down
26 changes: 11 additions & 15 deletions .env
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
# Base config
WP_ROOT_FOLDER="/app/wordpress/"
WP_ROOT_FOLDER="/var/www/html/"
WP_ADMIN_PATH="/wp-admin"

# Site config
WP_URL="https://beasanitizefilename.lndo.site"
WP_DOMAIN="beasanitizefilename.lndo.site"
WP_URL="http://localhost:8889"
WP_DOMAIN="localhost"

# database config
DB_NAME="wordpress"
DB_HOST="database"
DB_USER="wordpress"
DB_PASSWORD="wordpress"
DB_HOST="mysql"
DB_USER="root"
DB_PASSWORD="password"
TABLE_PREFIX="wp_"

# Unit Tests
TEST_DB_NAME="wpTests"
TEST_DB_HOST="database"
TEST_DB_USER="wordpress"
TEST_DB_PASSWORD="wordpress"
TEST_DB_NAME="wordpress_test"
TEST_DB_HOST="mysql"
TEST_DB_USER="root"
TEST_DB_PASSWORD="password"
TEST_TABLE_PREFIX="wp_"

# Admin access config
ADMIN_EMAIL="admin@beasanitizefilename.lndo.site"
ADMIN_EMAIL="admin@example.com"
ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin

# BrowserStack
# BROWSERSTACK_USERNAME_REAL=
# BROWSERSTACK_KEY=
17 changes: 7 additions & 10 deletions .github/workflows/release-version.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Upload Release Asset
name: Deploy to WordPress.org

on:
push:
Expand All @@ -7,12 +7,12 @@ on:
- '*' # Push events to matching *

jobs:
build:
name: Upload Release Asset
deploy:
name: Deploy to WordPress.org
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Publish to WP.org
uses: 10up/action-wordpress-plugin-deploy@stable
Expand All @@ -23,12 +23,9 @@ jobs:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SLUG: bea-sanitize-filename

- name: Upload Release
uses: actions/upload-release-asset@v1
- name: Upload release asset
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{github.workspace}}/${{ github.event.repository.name }}.zip
asset_name: bea-sanitize-filename.zip
asset_content_type: application/zip
files: ${{ github.workspace }}/bea-sanitize-filename.zip
61 changes: 22 additions & 39 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,30 @@ name: Tests

on: [pull_request]
jobs:
build:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest ]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Outdated checkout action version in tests workflow

Medium Severity

The tests workflow uses actions/checkout@v2 while the release workflow was updated to actions/checkout@v4 in the same PR. v2 relies on Node.js 12, which GitHub Actions has deprecated and will eventually stop supporting, meaning this workflow will start failing. This is clearly an oversight since the rest of the workflow was heavily modernized.

Additional Locations (1)
Fix in Cursor Fix in Web

php-versions: [ '7.4' ]
wordpress-versions: [ 'latest', 'nightly', '6.0', '5.9', '5.8', '5.7', '5.6', '5.5']
unit:
runs-on: ubuntu-latest

steps:
- name: "Checkout code"
uses: actions/checkout@v2

- name: "Install docker-ce"
run: |
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

- name: "Install Lando"
run: |
wget https://files.devwithlando.io/lando-stable.deb
sudo dpkg -i lando-stable.deb

- name: "Test on ${{ matrix.php-versions }} - ${{ matrix.wordpress-versions }}"
run: |
./bin/ci-env.sh
WP_VERSION=${{ matrix.wordpress-versions }} WP_LOCALE=en_US PHP_VERSION=${{ matrix.php-versions }} ./bin/lando-start.sh

- name: "Run tests"
run: |
lando test
lando stop
- name: "Setup Node.js"
uses: actions/setup-node@v4
with:
node-version: "18"

- name: "Install PHP dependencies"
run: composer install --no-interaction --prefer-dist

- name: "Install Node.js dependencies"
run: npm install

- name: "Start wp-env"
run: npm run wp-env:start

- name: "Run unit tests"
run: npm run test:unit

- name: "Stop wp-env"
if: always()
run: npm run wp-env:stop
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/vendor
/node_modules
.env.local
/wordpress

codeception.yml
tests/acceptance.suite.yml
tests/functional.suite.yml
tests/unit.suite.yml
tests/wpunit.suite.yml
.wp-env.override.json
.phpunit.result.cache

.idea/
.DS_STORE
44 changes: 0 additions & 44 deletions .lando.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"core": "WordPress/WordPress",
"phpVersion": "8.0",
"plugins": [
"."
],
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicate plugin mount in wp-env configuration

Medium Severity

The plugins array includes "." and mappings also mounts "." to wp-content/plugins/bea-sanitize-filename. This is a known wp-env anti-pattern that causes the plugin to be mounted twice — once under the workspace directory name and once under the explicit mapping name — resulting in duplicate entries in wp plugin list and potential activation under the wrong directory name. The "." entry in plugins is redundant when mappings already handles it.

Additional Locations (1)
Fix in Cursor Fix in Web

"mappings": {
"wp-content/plugins/bea-sanitize-filename": "."
},
"env": {
"tests": {
"phpVersion": "8.0",
"mappings": {
"wp-content/plugins/bea-sanitize-filename": "."
}
}
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.0.9 - 02 Apr 2026
* Fix invalid smart quotes in special characters list
* Migrate tests to `wp-env` with PHPUnit unit tests only
* Improve testing documentation and scripts

## 2.0.8 - 02 Apr 2026
* Add `@` character to the sanitized characters list

Expand Down
63 changes: 33 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# BEA - Sanitize Filename

Current version: `2.0.9`

This plugin will remove all punctuation and accents from the filename of uploaded files, which is pretty handy.
You could then ask "Why it's not already into core?". This is [make WordPress core](https://core.trac.wordpress.org/ticket/22363) !

Expand Down Expand Up @@ -45,43 +47,44 @@ An [issue](https://github.com/BeAPI/bea-sanitize-filename/issues/1) is open abou

### Introduction

The tests are based on [WP-Browser](https://github.com/lucatume/wp-browser).
The tests are based on PHPUnit and run inside [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/).

You have WPUnit and Acceptance tests.
Only unit tests are available.

### Installation

1. Install [Lando](https://docs.devwithlando.io/installation/installing.html)
2. From command line into the project folder execute `./bin/lando-start.sh`
3. From command line into the project folder execute `lando composer install`

The local url will be https://beasanitizefilename.lndo.site and credentials will be
* user : admin
* password : admin
1. Install [Docker](https://www.docker.com/) and [Node.js](https://nodejs.org/) (>= 18)
2. Install dependencies: `npm install && composer install`
3. Run tests: `npm run test:unit`

### Tools
To test the code, just launch :
* For Wpunit tests and desktop : `lando test-local`
* For desktop mobile : `lando test-mobile`

If you need to test the code on BrowserStack, you need to define two environments variables :
* `BROWSERSTACK_USERNAME_REAL` : the usernmae of your browserStack account
* `BROWSERSTACK_KEY` : the key of your browserStack account

/!\ Do not commit theses credentials /!\

## Customization

Need to customize the environment variables ? every codeception file can be overrided bit by bit by creating a new file without the .dist.
So to customize the .env file you'l need to :

* Create a codeception.yml file
* Put into the file :
```
params:
- .env.local
```
* Create a .env.local file and change the desired environment variables like `BROWSERSTACK_KEY`
* For unit tests: `npm run test:unit`
* For a readable report: `npm run test:unit:report`
* For one-shot start + test + stop: `npm run test:unit:once`

### Operating procedure

1. Initialize once on your machine:
- `npm install`
- `composer install`
2. Run test suite:
- `npm run test:unit`
3. Read result directly in terminal output:
- Success: exit code `0` and PHPUnit success line.
- Failure: exit code `1` or `2` with failing test names and stack traces.
4. Stop environment if needed:
- `npm run wp-env:stop`

### Troubleshooting

- Error `service "cli" is not running`:
- `npm run wp-env:start`
- `npm run test:unit`
- If environment is corrupted:
- `npm run wp-env:clean`
- `npm run wp-env:start`
- `npm run test:unit`

## Changelog
Please refer to the [contributing guidelines](.github/CONTRIBUTING.md) to increase the chance of your pull request to be merged and/or receive the best support for your issue.
Expand Down
4 changes: 2 additions & 2 deletions bea-sanitize-filename.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: BEA - Sanitize Filename
Version: 2.0.8
Version: 2.0.9
Plugin URI: https://github.com/BeAPI/bea-sanitize-filename
Description: Remove all punctuation and accents from the filename of uploaded files.
Author: Be API
Expand Down Expand Up @@ -38,7 +38,7 @@
*/
function bea_sanitize_file_name_chars( $special_chars = array() ) {
// Special caracters
$special_chars = array_merge( array( ‘’’, ‘’’, ‘”’, ‘”’, ‘«’, ‘»’, ‘‹’, ‘›’, ‘—‘, ‘€’, ‘©’, ‘@’ ), $special_chars );
$special_chars = array_merge( array( '’', '‘', '”', '“', '«', '»', '‹', '›', '—', '€', '©', '@' ), $special_chars );
/**
* Accentued caracters
* @see https://github.com/BeAPI/bea-sanitize-filename/issues/8
Expand Down
5 changes: 0 additions & 5 deletions bin/ci-env.sh

This file was deleted.

23 changes: 0 additions & 23 deletions bin/install-wp-cli.sh

This file was deleted.

2 changes: 0 additions & 2 deletions bin/lando-browserstack.sh

This file was deleted.

Loading
Loading