Giter VIP home page Giter VIP logo

zsh-escape's Introduction

Zsh Escape

Zsh Escape is a Zsh script for finding and automatically fixing unescaped variables in Zsh scripts.

Prerequisites

  • zsh
  • gawk

Installation

TODO

Usage

Report

It can be helpful to run the report command first. This will go through each line in a file and print the line number followed by any potential errors.

zsh-escape.zsh report [OPTION]... [FILE]...

Options

Option Value Description
-d --debug Includes debugging output.
-o --output <file> Writes the output to a file.

Example

$ cat unescaped-test-simple.zsh
| if [[ $FOO == false ]]; then
|   echo "FALSE"
| fi
$ zsh-escape.zsh report unescaped-test-simple.zsh
| 1: if [[ $FOO == false ]]; then
| - Unescaped parameter expansion: $FOO
| - Found 1 unescaped expansion
| 2:   echo "FALSE"
| 3: fi

This shows that it found an unescaped variable $FOO.

Fix

The fix command will automatically add missing quotes around unescaped variables.

zsh-escape.zsh fix [OPTION]... [FILE]...

Be careful if editing a file in place. It is recommended that you create a backup of the file first or commit it to source control.

Options

Option Value Description
-d --debug Includes debugging output. Only use this to debug issues, it is better suited to the report command instead.
-i --in-place This will cause the file to be edited in place.
-o --output <file> Writes the output to a file. Only applicable if there is a single input file.

Example

$ cat unescaped-test-simple.zsh
| if [[ $FOO == false ]]; then
|   echo "FALSE"
| fi
$ zsh-escape.zsh fix unescaped-test-simple.zsh
| if [[ "$FOO" == false ]]; then
|   echo "FALSE"
| fi

zsh-escape's People

Contributors

steinybot avatar

Watchers

 avatar

zsh-escape's Issues

Regex pattern should not be escaped

Description

A clear and concise description of what the bug is.

Versions

Component Version
Zsh Escape da39a3ee5e6b4b0d3255bfef95601890afd80709 (git rev-parse HEAD)
OS Windows 10
Zsh zsh 5.5.1 (i686-pc-cygwin) (zsh --version)

Steps To Reproduce

Steps to reproduce the bug:

  1. Use the following file bad-script.zsh:
dir=$1
cd $dir
  1. Run:
zsh-escape.zsh report bad-script.zsh

Expected Behaviour

A clear and concise description of what you expected to happen.

Actual Behaviour

A clear and concise description of what actually happened.

Screenshots and/or Logs

Add screenshots and/or logs to help explain your problem.

Additional Context

Add any other context about the problem here.

Variables in arithmetic evaluation should not be escaped

Description

Variables in arithmetic evaluation are being escaped but this changes the value from a number to a string and so the arithmetic operation fails.

Versions

Component Version
Zsh Escape 44a1d7f
OS Windows 10
Zsh zsh 5.5.1 (i686-pc-cygwin)

Steps To Reproduce

Steps to reproduce the bug:

  1. Use the following file bad-script.zsh:
i=0 && if (( $i + 1 )); then echo true; else echo false; fi
  1. Run:
zsh-escape.zsh report bad-script.zsh

Expected Behaviour

1 : i=0 && if (( $i + 1 )); then echo true; else echo false; fi

Actual Behaviour

1 : i=0 && if (( $i + 1 )); then echo true; else echo false; fi
- Unescaped variable: $i
- Found an unescaped variable

Command substitutions with nested parentheses are not escaped correctly

Description

Command substitutions that contains nested parentheses (e.g. with a nested parameter expansion containing a flag) are not escaped correctly.

Versions

Component Version
Zsh Escape a04551a (git rev-parse HEAD)
OS Windows 10
Zsh zsh 5.5.1 (i686-pc-cygwin) (zsh --version)

Steps To Reproduce

Steps to reproduce the bug:

  1. Use the following file bad-script.zsh:
foo=$(print ${(qq)bar})
  1. Run:
zsh-escape.zsh fix bad-script.zsh

Expected Behaviour

foo="$(print ${(qq)bar})"

Actual Behaviour

foo="$(print ${(qq)"bar})

Arrays are not escaped correctly

Description

Arrays are not escaped correctly.

Versions

Component Version
Zsh Escape 3fe0017
OS Windows 10
Zsh zsh 5.0.6 (i686-pc-cygwin)

Steps To Reproduce

Steps to reproduce the bug:

  1. Use the following file bad-script.zsh:
echo $commands[git]
  1. Run:
zsh-escape.zsh report bad-script.zsh

Expected Behaviour

It can escape the full array substitution.

1 : echo $commands[git]
- Unescaped variable: $commands[git]
- Found an unescaped variable

Actual Behaviour

It thinks that the variable ends before the [].

1 : echo $commands[git]
- Unescaped variable: $commands
- Found an unescaped variable

Multi-line command substitution does not work

Description

A multi-line command substitution is not escaped.

Versions

Component Version
Zsh Escape 3fe0017
OS Windows 10
Zsh zsh 5.0.6 (i686-pc-cygwin)

Steps To Reproduce

Steps to reproduce the bug:

  1. Use the following file bad-script.zsh:
    ref=$(abc \
	    || def)
  1. Run:
zsh-escape.zsh report -d bad-script.zsh

Expected Behaviour

The report finds the start and the end of the command substitution (and fix can escape it).

1 :     ref=$(abc \
DEBUG: Start of command substitution
- Unescaped substitution: $(abc \
- Found an unescaped command substitution
2 : 	    || def)
DEBUG: End of command substitution
- Unescaped substitution: 	    || def)

Actual Behaviour

It thinks that there is a variable with no name.

1 :     ref=$(abc \
- Unescaped variable: $
- Found an unescaped variable
2 : 	    || def)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.