lando / leia

A testing utility that tests code blocks in documentation.
GNU General Public License v3.0
17 stars 4 forks source link

How to handle lots of quote recursion in an execute string... #21

Open tobybellwood opened 3 years ago

tobybellwood commented 3 years ago

We're using Leia - because it's awesome - to do some testing, and have hit a stumbling block around nesting ' and "...

If I have the line

docker-compose exec -T php sh -c "sed -i \'1 aremove_filter('template_redirect','redirect_canonical');' /app/web/content/themes/twentytwenty/functions.php"

because I want the second line of my functions.php file to be remove_filter('template_redirect','redirect_canonical');

How could I go about quoting it, so that mocha doesn't freak out...

/home/tobybellwood/sites/wordpress-example/test/docker-compose-wordpress-simple-php-7-4-nginx-mariadb.func.js:225
    cli.exec('docker-compose exec -T php sh -c "sed -i '1 aremove_filter('template_redirect','redirect_canonical');' /app/web/content/themes/twentytwenty/functions.php"').then(res => {
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

adding a \ before the ' works for mocha but doesn't do anything

    cli.exec('docker-compose exec -T php sh -c "sed -i \'1 aremove_filter(\'template_redirect\',\'redirect_canonical\');\' /app/web/content/themes/twentytwenty/functions.php"').then(res => {

If there's no easy fix, I can just find a way that doesn't involve single quotes :scream:

pirog commented 2 years ago

@tobybellwood i think we are going to leverage this stringargv module which, if works as advertised should be able to handle this.