[PR #6556] [MERGED] build: sort.py: strip whitespace in profiles #6060

Closed
opened 2026-05-05 10:49:57 -06:00 by gitea-mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netblue30/firejail/pull/6556
Author: @kmk3
Created: 11/29/2024
Status: Merged
Merged: 12/5/2024
Merged by: @kmk3

Base: masterHead: sort-py-strip-ws


📝 Commits (4)

  • ced8b19 build: sort.py: operate mostly on fixed_line
  • 406b1cb build: sort.py: rename line variables
  • 53ff8e0 build: sort.py: strip trailing whitespace in all lines
  • 08e5f81 build: sort.py: strip whitespace in commands

📊 Changes

1 file changed (+21 additions, -14 deletions)

View changed files

📝 contrib/sort.py (+21 -14)

📄 Description

build: sort.py: strip trailing whitespace in all lines

Currently the output is mangled if the last item on the line contains
trailing whitespace and is moved when sorting.

So remove trailing whitespace in all lines (that is, not just in lines
containing supported commands).

Leave leading whitespace as is for now since it could potentially be
used for indentation.

Before:

$ printf '# hello world  \nprivate-bin a,b  \nprivate-bin b,a  \nprivate-bin  a,b\n' \
  >foo.profile
$ ./contrib/sort.py -n foo.profile | tr ' ' .
sort.py:.checking.1.profile(s)...
foo.profile:3:-private-bin.b,a..
foo.profile:3:+private-bin.a..,b

After:

$ printf '# hello world  \nprivate-bin a,b  \nprivate-bin b,a  \n' \
  >foo.profile
$ ./contrib/sort.py -n foo.profile | tr ' ' .
sort.py:.checking.1.profile(s)...
foo.profile:1:-#.hello.world..
foo.profile:1:+#.hello.world
foo.profile:2:-private-bin.a,b..
foo.profile:2:+private-bin.a,b
foo.profile:3:-private-bin.b,a..
foo.profile:3:+private-bin.a,b

build: sort.py: strip whitespace in commands

Currently whitespace is left as is within an entry.

In a protocol entry, if there is whitespace between the command and
its argument or around an item, the item in question is dropped from the
output.

Changes:

  • protocol: Strip all whitespace in the argument
  • Other commands: Strip leading/trailing whitespace around each item,
    including any extra whitespace between a command and its argument

Note: Whitespace characters inside paths are left as is, as some paths
(such as Foo Bar may contain spaces.

Before:

$ printf 'private-bin a,b\nprivate-bin  a,b\nprivate-bin  b,a\nprivate-bin  C,A  B\nprotocol  unix,net\nprotocol  inet,unix\n' \
  >foo.profile
$ ./contrib/sort.py -n foo.profile
sort.py: checking 1 profile(s)...
foo.profile:5:-protocol  unix,net
foo.profile:5:+protocol
foo.profile:6:-protocol  inet,unix
foo.profile:6:+protocol unix

After:

$ printf 'private-bin a,b\nprivate-bin  a,b\nprivate-bin  b,a\nprivate-bin  C,A  B\nprotocol  unix,net\nprotocol  inet,unix\n' \
  >foo.profile
$ ./contrib/sort.py -n foo.profile
sort.py: checking 1 profile(s)...
foo.profile:2:-private-bin  a,b
foo.profile:2:+private-bin a,b
foo.profile:3:-private-bin  b,a
foo.profile:3:+private-bin a,b
foo.profile:4:-private-bin  C,A  B
foo.profile:4:+private-bin A  B,C
foo.profile:5:-protocol  unix,net
foo.profile:5:+protocol unix
foo.profile:6:-protocol  inet,unix
foo.profile:6:+protocol unix,inet

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netblue30/firejail/pull/6556 **Author:** [@kmk3](https://github.com/kmk3) **Created:** 11/29/2024 **Status:** ✅ Merged **Merged:** 12/5/2024 **Merged by:** [@kmk3](https://github.com/kmk3) **Base:** `master` ← **Head:** `sort-py-strip-ws` --- ### 📝 Commits (4) - [`ced8b19`](https://github.com/netblue30/firejail/commit/ced8b19dbeb5cf23df6f57ed11c04b7458a676e0) build: sort.py: operate mostly on fixed_line - [`406b1cb`](https://github.com/netblue30/firejail/commit/406b1cb18ebd463f00a437f43335d4a010b6fe05) build: sort.py: rename line variables - [`53ff8e0`](https://github.com/netblue30/firejail/commit/53ff8e0ad9775885e3ae0740947507ddf9f2d7bc) build: sort.py: strip trailing whitespace in all lines - [`08e5f81`](https://github.com/netblue30/firejail/commit/08e5f8161c749616a798aeb66b0246ac39505d6c) build: sort.py: strip whitespace in commands ### 📊 Changes **1 file changed** (+21 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `contrib/sort.py` (+21 -14) </details> ### 📄 Description build: sort.py: strip trailing whitespace in all lines Currently the output is mangled if the last item on the line contains trailing whitespace and is moved when sorting. So remove trailing whitespace in all lines (that is, not just in lines containing supported commands). Leave leading whitespace as is for now since it could potentially be used for indentation. Before: $ printf '# hello world \nprivate-bin a,b \nprivate-bin b,a \nprivate-bin a,b\n' \ >foo.profile $ ./contrib/sort.py -n foo.profile | tr ' ' . sort.py:.checking.1.profile(s)... foo.profile:3:-private-bin.b,a.. foo.profile:3:+private-bin.a..,b After: $ printf '# hello world \nprivate-bin a,b \nprivate-bin b,a \n' \ >foo.profile $ ./contrib/sort.py -n foo.profile | tr ' ' . sort.py:.checking.1.profile(s)... foo.profile:1:-#.hello.world.. foo.profile:1:+#.hello.world foo.profile:2:-private-bin.a,b.. foo.profile:2:+private-bin.a,b foo.profile:3:-private-bin.b,a.. foo.profile:3:+private-bin.a,b --- build: sort.py: strip whitespace in commands Currently whitespace is left as is within an entry. In a `protocol` entry, if there is whitespace between the command and its argument or around an item, the item in question is dropped from the output. Changes: * `protocol`: Strip all whitespace in the argument * Other commands: Strip leading/trailing whitespace around each item, including any extra whitespace between a command and its argument Note: Whitespace characters inside paths are left as is, as some paths (such as `Foo Bar` may contain spaces. Before: $ printf 'private-bin a,b\nprivate-bin a,b\nprivate-bin b,a\nprivate-bin C,A B\nprotocol unix,net\nprotocol inet,unix\n' \ >foo.profile $ ./contrib/sort.py -n foo.profile sort.py: checking 1 profile(s)... foo.profile:5:-protocol unix,net foo.profile:5:+protocol foo.profile:6:-protocol inet,unix foo.profile:6:+protocol unix After: $ printf 'private-bin a,b\nprivate-bin a,b\nprivate-bin b,a\nprivate-bin C,A B\nprotocol unix,net\nprotocol inet,unix\n' \ >foo.profile $ ./contrib/sort.py -n foo.profile sort.py: checking 1 profile(s)... foo.profile:2:-private-bin a,b foo.profile:2:+private-bin a,b foo.profile:3:-private-bin b,a foo.profile:3:+private-bin a,b foo.profile:4:-private-bin C,A B foo.profile:4:+private-bin A B,C foo.profile:5:-protocol unix,net foo.profile:5:+protocol unix foo.profile:6:-protocol inet,unix foo.profile:6:+protocol unix,inet --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
gitea-mirror 2026-05-05 10:49:57 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/firejail#6060
No description provided.