Skip to content

Commit bc5269f

Browse files
committed
Trim whitespace from unit files while parsing
Fixes: containers#18979 Signed-off-by: Daniel J Walsh <[email protected]>
1 parent 3846388 commit bc5269f

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repos:
1212
- id: end-of-file-fixer
1313
exclude: test/buildah-bud/buildah-tests.diff
1414
- id: trailing-whitespace
15-
exclude: test/buildah-bud/buildah-tests.diff
15+
exclude: test/buildah-bud/buildah-tests.diff|test/e2e/quadlet/remap-keep-id2.container
1616
- id: mixed-line-ending
1717
- id: check-byte-order-marker
1818
- id: check-executables-have-shebangs

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ help: ## (Default) Print listing of key targets with their descriptions
253253
.PHONY: .gitvalidation
254254
.gitvalidation:
255255
@echo "Validating vs commit '$(call err_if_empty,EPOCH_TEST_COMMIT)'"
256-
GIT_CHECK_EXCLUDE="./vendor:./test/tools/vendor:docs/make.bat:test/buildah-bud/buildah-tests.diff" ./test/tools/build/git-validation -run DCO,short-subject,dangling-whitespace -range $(EPOCH_TEST_COMMIT)..$(HEAD)
256+
GIT_CHECK_EXCLUDE="./vendor:./test/tools/vendor:docs/make.bat:test/buildah-bud/buildah-tests.diff:test/e2e/quadlet/remap-keep-id2.container" ./test/tools/build/git-validation -run DCO,short-subject,dangling-whitespace -range $(EPOCH_TEST_COMMIT)..$(HEAD)
257257

258258
.PHONY: lint
259259
lint: golangci-lint

pkg/systemd/parser/unitfile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func (p *UnitFileParser) flushPendingComments(toComment bool) {
373373
func nextLine(data string, afterPos int) (string, string) {
374374
rest := data[afterPos:]
375375
if i := strings.Index(rest, "\n"); i >= 0 {
376-
return data[:i+afterPos], data[i+afterPos+1:]
376+
return strings.TrimSpace(data[:i+afterPos]), data[i+afterPos+1:]
377377
}
378378
return data, ""
379379
}

test/e2e/quadlet/remap-keep-id2.container

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[Container]
44
Image=localhost/imagename
5-
RemapUsers=keep-id
5+
# The added three spaces to keep-id are necessary for test of trimwhitespace
6+
RemapUsers=keep-id
67
RemapUid=200
78
RemapGid=210

0 commit comments

Comments
 (0)