Skip to content

append() does not respect current content if line contains '<' #1294

Description

@ecksun

I noticed that if I run append() several times with the same content it also appends that line several times, instead of just one time. That is, append() is not idempotent.

If text is already found in filename, the append is not run, and None is returned immediately.

The following small test script can reproduce the issue:

from fabric.contrib.files import append

def run():
      append('testfile', 'some < pipe')

This issue seems to be similar to #341

The error has to do with the '<' symbol.

The problem seems to boil down to the regex that is sent to egrep in contains():
https://github.com/fabric/fabric/blob/master/fabric/contrib/files.py#L360

printing egrep_cmd gives me the following for the above testcase:

egrep "^some\ \<\ pipe$" "$(echo testfile)"

However the correct regex would be:

egrep "^some\ <\ pipe$" "$(echo testfile)"

The incorrect regex seems to be generated by the _escape_for_regex function.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions