saltstack/salt — Issue #751: file.append state broken on lines containing some characters.
Author: kladiin
Created: 2012-02-24 15:11:08+00:00
State: open

# To reproduce:

## State file

```yaml
/tmp/foo:
file:
- append
- text:
- a+b
```

## Run

> salt testminion state.highstate
> salt testminion state.highstate

## Expectation

`/tmp/foo` contains one line containing `a+b`.

## Actual results

`/tmp/foo` contains two lines containing `a+b`.

# Reason for bug

The `file.append` state calls the `file.contains` module on each line before calling the `file.append` module to append the line to the file. However, `file.contains` assumes that the text passed to it is a regular expression, suitable to be passed to the `file.sed` module directly. This means that for the line `a+b`, `file.contains` is looking for a line consisting of one or more instances of the letter `a`, followed directly by the letter `b`, rather than searching for the string `a+b`.

Another symptom of this is that a line containing only `+` will cause sed to simply throw an error, and another is that a line `foo` may be matched by an existing line in the file containing `barfooxyz`.

# Possible resolution

Modify `file.contains` to scan the file for the line without using `file.sed`. Find other modules that may be subject to this bug.