Skip to content

[master] Fix insertion of a line with special characters#65155

Closed
berkut-174 wants to merge 0 commit intosaltstack:masterfrom
berkut-174:master
Closed

[master] Fix insertion of a line with special characters#65155
berkut-174 wants to merge 0 commit intosaltstack:masterfrom
berkut-174:master

Conversation

@berkut-174
Copy link
Contributor

What does this PR do?

This PR fixes the insertion of a line into a file when a state like this is used:

/etc/security/group.conf:
  file.line:
    - create: True
    - mode: insert
    - location: end
    - content: '*; *; *; Al0000-24000; wheel'

Previous Behavior

----------
          ID: /etc/security/group.conf
    Function: file.line
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/opt/saltstack/salt/run/salt/modules/file.py", line 1729, in _regex_to_static
                  compiled = re.compile(regex, re.DOTALL)
                File "re.py", line 252, in compile
                File "re.py", line 304, in _compile
                File "sre_compile.py", line 788, in compile
                File "sre_parse.py", line 955, in parse
                File "sre_parse.py", line 444, in _parse_sub
                File "sre_parse.py", line 669, in _parse
              re.error: nothing to repeat at position 0
              
              During handling of the above exception, another exception occurred:
              
              Traceback (most recent call last):
                File "salt/state.py", line 2276, in call
                  ret = self.states[cdata["full"]](
                File "salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "salt/loader/lazy.py", line 1276, in wrapper
                  return f(*args, **kwargs)
                File "/opt/saltstack/salt/run/salt/states/file.py", line 5094, in line
                  changes = __salt__["file.line"](
                File "salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/opt/saltstack/salt/run/salt/modules/file.py", line 2282, in line
                  body = _set_line(
                File "/opt/saltstack/salt/run/salt/modules/file.py", line 1874, in _set_line
                  match = _regex_to_static(lines, match)
                File "/opt/saltstack/salt/run/salt/modules/file.py", line 1732, in _regex_to_static
                  raise CommandExecutionError("{}: '{}'".format(_get_error_message(ex), regex))
              salt.exceptions.CommandExecutionError: nothing to repeat at position 0: '*; *; *; Al0000-24000; wheel'

New Behavior

----------
          ID: /etc/security/group.conf
    Function: file.line
      Result: True
     Comment: Changes were made
     Started: 14:58:17.352513
    Duration: 54.279 ms
     Changes:   
              ----------
              diff:
                  --- 
                  +++ 
                  @@ -105,3 +105,5 @@
                   # End of group.conf file
                   #
                   
                  +
                  +*; *; *; Al0000-24000; wheel

@berkut-174 berkut-174 requested a review from a team as a code owner September 8, 2023 10:59
@berkut-174 berkut-174 requested review from Ch3LL and removed request for a team September 8, 2023 10:59
@salt-project-bot-prod-environment salt-project-bot-prod-environment bot changed the title Fix insertion of a line with special characters [master] Fix insertion of a line with special characters Sep 8, 2023
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 11:17 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 11:17 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 11:17 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 11:17 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 11:35 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 11:38 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 12:38 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 12:38 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 12:38 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 12:39 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 12:39 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 12:39 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 13:17 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 13:17 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 13:17 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 13:17 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 13:18 — with GitHub Actions Inactive
@berkut-174 berkut-174 temporarily deployed to ci September 8, 2023 13:18 — with GitHub Actions Inactive
@dwoz
Copy link
Contributor

dwoz commented Sep 9, 2023

This will need to be very thoroughly tested. Historically, any changes to the file module are prone to introduce unforseen bugs.

@dwoz dwoz added this to the Argon v3008.0 milestone Dec 18, 2023
@dwoz dwoz requested a review from a team as a code owner March 16, 2025 22:09
@twangboy
Copy link
Contributor

twangboy commented Apr 1, 2025

This will also need a changelog and some tests.

@twangboy twangboy added the test:full Run the full test suite label Apr 1, 2025
@twangboy twangboy added needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases needs-changelog labels Jul 2, 2025
@bdrx312
Copy link
Contributor

bdrx312 commented Oct 14, 2025

@berkut-174 Nice change. The code change looks correct. Can you add a test?

@berkut-174 berkut-174 closed this Feb 12, 2026
@dwoz dwoz temporarily deployed to workflow-restart February 13, 2026 00:08 — with GitHub Actions Inactive
@dwoz dwoz temporarily deployed to workflow-restart February 13, 2026 00:08 — with GitHub Actions Inactive
@dwoz dwoz deployed to workflow-restart February 13, 2026 00:08 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-changelog needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants