diff options
author | Andreas Fankhauser hiddenalpha.ch | 2022-12-15 14:33:08 +0100 |
---|---|---|
committer | Andreas Fankhauser hiddenalpha.ch | 2022-12-15 14:33:08 +0100 |
commit | 06fae3ad8b2892b1a6ca674a66559b0186e60f39 (patch) | |
tree | e679e61d947e3d8e27d8eedc4b55cc71b5da8e79 | |
parent | 3ccecb63de019cb649a89a8e828b47e60c4d9cc4 (diff) | |
parent | 0886d4aa4dbac1cb93c47c9a7986d13013af1c6f (diff) | |
download | UnspecifiedGarbage-06fae3ad8b2892b1a6ca674a66559b0186e60f39.zip UnspecifiedGarbage-06fae3ad8b2892b1a6ca674a66559b0186e60f39.tar.gz |
Merge upstream changes from master to feature
-rw-r--r-- | doc/note/links/links.txt | 7 | ||||
-rw-r--r-- | src/main/java/ch/hiddenalpha/unspecifiedgarbage/shell/ShellUtils.java | 41 |
2 files changed, 47 insertions, 1 deletions
diff --git a/doc/note/links/links.txt b/doc/note/links/links.txt index a3b680d..3ca26ba 100644 --- a/doc/note/links/links.txt +++ b/doc/note/links/links.txt @@ -151,6 +151,8 @@ Links (Aka arguments) - [static final java uppercase](https://gitit.post.ch/projects/ISA/repos/preflux/pull-requests/82/overview?commentId=39126) - [invalid java class name](https://gitit.post.ch/projects/ISA/repos/preflux/pull-requests/82/overview?commentId=39125) - [Formatters produce crap](https://gitit.post.ch/projects/ISA/repos/minetti/pull-requests/14/overview) +- [Formatters produce crap](https://gitit.post.ch/projects/ISA/repos/veet/pull-requests/2/overview?commentId=233638) +- [Suddenly NEW formatting rules in PaISA since 2021](https://gitit.post.ch/projects/ISA/repos/watson/pull-requests/1/overview?commentId=234597) - "https://gitit.post.ch/projects/ISA/repos/zarniwoop/pull-requests/20/overview?commentId=85912" - "https://gitit.post.ch/projects/ISA/repos/zarniwoop/pull-requests/21/overview?commentId=87250" - "https://gitit.post.ch/projects/ISA/repos/beeble/pull-requests/126/overview?commentId=70762" @@ -167,6 +169,8 @@ Links (Aka arguments) ## Sonar is stupid - "https://gitit.post.ch/projects/ZEWAS/repos/zewas/browse/zewas-process/src/main/java/ch/post/it/zewas/process/reportgenerator/sql/SqlReportGenerator.java?at=refs%2Ftags%2Fzewas-17.10.00.17#385" - "https://gitit.post.ch/projects/ISA/repos/platform/pull-requests/156" +- [Deprecated is a blocker](https://gitit.post.ch/projects/ISA/repos/preflux/pull-requests/562/overview?commentId=234158) +- [Deprecated is a blocker](https://wikit.post.ch/pages/viewpage.action?pageId=716936486#ISASonarProfil-SuppressWarningsAnnotation) ## Plain Old Data (POD, POJO, DTO) - "https://de.wikipedia.org/wiki/Plain_Old_Data_structure#PODs_in_Java" @@ -373,7 +377,7 @@ Links (Aka arguments) - "https://gitit.post.ch/projects/ISA/repos/preflux/pull-requests/119/overview?commentId=46245" ## Input validation -- WontDo "https://gitit.post.ch/projects/ISA/repos/preflux/pull-requests/512/overview?commentId=222672" +- [WontDo](https://gitit.post.ch/projects/ISA/repos/preflux/pull-requests/512/overview?commentId=222672) ## Git for windoof CRLF broken - "https://wikit.post.ch/display/ISA/Code+Formatting?focusedCommentId=791239536#comment-791239536" @@ -400,6 +404,7 @@ Links (Aka arguments) ## Automatic variable dynamic version are evil - [Apikana broken by design](https://gitit.post.ch/projects/ISA/repos/notifications-api/pull-requests/7/overview?commentId=232144) +- [Apikana broken by design](https://gitit.post.ch/projects/ISA/repos/deployment-playbook-api/pull-requests/11/overview?commentId=234691) ## Encoding mime application/octet-stream string utf8 unicode json payload data - [eagle queue browser](https://gitit.post.ch/projects/ISA/repos/eagle/pull-requests/331/overview?commentId=232322) diff --git a/src/main/java/ch/hiddenalpha/unspecifiedgarbage/shell/ShellUtils.java b/src/main/java/ch/hiddenalpha/unspecifiedgarbage/shell/ShellUtils.java new file mode 100644 index 0000000..5e2aff2 --- /dev/null +++ b/src/main/java/ch/hiddenalpha/unspecifiedgarbage/shell/ShellUtils.java @@ -0,0 +1,41 @@ +package ch.hiddenalpha.unspecifiedgarbage.shell; + + +public class ShellUtils { + + /** + * Escapes the string so we can use the result in a + * <a href="https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_02_03">double-quoted shell string</a>. + * But keeps <a href="https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02">parameter expansion</a> alive. + * Example usage: + * String path = "pâth \\with ${varToResolve} but a|so €vil chars like spaces, p|pes or * asterisk"; + * cmd = "ls '"+ escapeForSnglQuotEverything(path) +"'"; + */ + public static String escapeForDblQuotButParams( String s ){ + s = s.replace("\\", "\\\\"); + s = s.replace("\"", "\\\""); + s = s.replace("`", "\\`"); + // do NOT escape '$' as we want to keep parameter expansion. + return s; + } + + /** + * Escapes the string so we can use result in a + * <a href="https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_02_02">single-quoted shell string</a>. + * Example usage: + * String path = "pâth \\with ${MustNotResolveThisVar} and a|so €vil chars like spaces, p|pes or * asterisk"; + * cmd = "ls '"+ escapeForSnglQuotEverything(path) +"'"; + */ + public static String escapeForSingleQuotEverything( String s ){ + // Cited from "Single-Quotes" in "https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html": + // Enclosing characters in single-quotes shall preserve the literal + // value of each character within the single-quotes. A single-quote + // cannot occur within single-quotes. + // Cited from "Double-Quotes" in "https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html": + // Enclosing characters in double-quotes ( "" ) shall preserve the + // literal value of all characters within the double-quotes, with the + // exception of the characters dollar sign, backquote, and backslash + return s.replace("'", "'\"'\"'"); + } + +} |