From ae2a605b4a438f0fb7c36878ef46651a5253fe5f Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Fri, 9 Dec 2022 17:21:10 +0100 Subject: Add ShellUtils.java. Add link --- doc/note/links/links.txt | 1 + .../unspecifiedgarbage/shell/ShellUtils.java | 41 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/java/ch/hiddenalpha/unspecifiedgarbage/shell/ShellUtils.java diff --git a/doc/note/links/links.txt b/doc/note/links/links.txt index a3b680d..cdc8016 100644 --- a/doc/note/links/links.txt +++ b/doc/note/links/links.txt @@ -151,6 +151,7 @@ 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) - "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" 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 + * double-quoted shell string. + * But keeps parameter expansion 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 + * single-quoted shell string. + * 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("'", "'\"'\"'"); + } + +} -- cgit v1.1 From 0886d4aa4dbac1cb93c47c9a7986d13013af1c6f Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Thu, 15 Dec 2022 14:29:41 +0100 Subject: (links) Add some links --- doc/note/links/links.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/note/links/links.txt b/doc/note/links/links.txt index cdc8016..3ca26ba 100644 --- a/doc/note/links/links.txt +++ b/doc/note/links/links.txt @@ -152,6 +152,7 @@ Links (Aka arguments) - [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" @@ -168,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" @@ -374,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" @@ -401,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) -- cgit v1.1