saltstack / saltstack/salt

file.replace with prepend_if_not_found prepends backslashes as literals

Open
#54,428 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Confirmed severity-medium
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Problem

file.replace with prepend_if_not_found=True prepends backslashes in repl content as literals, regardless of backslash_literal value

Example

Using repl containing tab

empty file, value is prepended as literal:

# salt-call file.replace /tmp/test pattern='my_content.*' repl='my_content\tnew_content' prepend_if_not_found=True backup=False backslash_literal=False
local:
    ---
    +++
    @@ -0,0 +1 @@
    +my_content\tnew_content
# cat /tmp/test
my_content\tnew_content

same file, replace the pattern, value is replaced with backslashes interpreted:

# salt-call file.replace /tmp/test pattern='my_content.*' repl='my_content\tnew_content' prepend_if_not_found=True backup=False backslash_literal=False
local:
    ---
    +++
    @@ -1 +1 @@
    -my_content\tnew_content
    +my_content new_content
# cat /tmp/test
my_content      new_content

providing not_found_content does not change the behaviour, still prepended as literal:

# salt-call file.replace /tmp/test pattern='my_content.*' repl='my_content\tnew_content' not_found_content='my_content\tnew_content' prepend_if_not_found=True backup=False backslash_literal=False 
local:
    ---
    +++
    @@ -0,0 +1 @@
    +my_content\tnew_content
# cat /tmp/test
my_content\tnew_content

Version:

Salt Version:
           Salt: 2019.2.0

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 1.5
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: 0.31.0
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: 1.2.5
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: 3.6.1
         pygit2: Not Installed
         Python: 2.7.5 (default, Aug  6 2019, 09:12:32)
   python-gnupg: 0.4.3
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: redhat 7.7 Valery Bykovsky
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-962.3.2.lve1.5.24.10.el7.x86_64
         system: Linux
        version: CloudLinux 7.7 Valery Bykovsky

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the documented salt-call file.replace commands, then inspect the file.replace handling for prepend_if_not_found, repl, not_found_content, and backslash_literal. Done means prepended content interprets backslash escapes consistently with replacement content when backslash_literal=False, with coverage for the shown cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.