You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by PascalSchumacher <gi...@git.apache.org> on 2016/11/04 18:43:35 UTC

[GitHub] commons-lang pull request #208: LANG-1066: Add shell/XSI escape/unescape sup...

GitHub user PascalSchumacher opened a pull request:

    https://github.com/apache/commons-lang/pull/208

    LANG-1066: Add shell/XSI escape/unescape support

    patch supplied by Mark

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/PascalSchumacher/commons-lang shell_xsi_escape_unescape_support

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/commons-lang/pull/208.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #208
    
----
commit 003ce0723989586685333156124fa3fc441dbdd8
Author: pascalschumacher <pa...@gmx.net>
Date:   2016-11-04T18:38:53Z

    LANG-1066: Add shell/XSI escape/unescape support
    
    patch supplied by Mark

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] commons-lang pull request #208: LANG-1066: Add shell/XSI escape/unescape sup...

Posted by PascalSchumacher <gi...@git.apache.org>.
Github user PascalSchumacher commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/208#discussion_r88799517
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java ---
    @@ -413,6 +447,47 @@ public int translate(final CharSequence input, final int index, final Writer out
             }
         }
     
    +    public static final CharSequenceTranslator UNESCAPE_XSI = new BackslashUnescaper();
    +
    +    /**
    +     * Translator object for unescaping backslash escaped entries.
    +     *
    +     * @since 3.6
    +     */
    +    static class BackslashUnescaper extends CharSequenceTranslator {
    --- End diff --
    
    No sure why the author of the patch choose this naming. I'm fine with changing it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] commons-lang issue #208: LANG-1066: Add shell/XSI escape/unescape support

Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:

    https://github.com/apache/commons-lang/pull/208
  
    
    [![Coverage Status](https://coveralls.io/builds/8904313/badge)](https://coveralls.io/builds/8904313)
    
    Coverage decreased (-0.02%) to 93.652% when pulling **a1e4319d9f7a13a1d162c4e077dbd0f25ae24910 on PascalSchumacher:shell_xsi_escape_unescape_support** into **dfd69e038cc7035031d1807c4ade870d2a7e2ece on apache:master**.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Fwd: [GitHub] commons-lang pull request #208: LANG-1066: Add shell/XSI escape/unescape sup...

Posted by Gary Gregory <ga...@gmail.com>.
I think this belongs in [text]. I am not -1 but let's see how the
discussion does in the other thread.

Gary

---------- Forwarded message ----------
From: britter <gi...@git.apache.org>
Date: Sat, Nov 19, 2016 at 3:37 AM
Subject: [GitHub] commons-lang pull request #208: LANG-1066: Add shell/XSI
escape/unescape sup...
To: issues@commons.apache.org


Github user britter commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/208#discussion_r88777926

    --- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java
---
    @@ -801,4 +876,61 @@ public static final String unescapeCsv(final
String input) {
             return UNESCAPE_CSV.translate(input);
         }

    +    // Shell
    +    /**
    +     * <p>Escapes the characters in a {@code String} using XSI
rules.</p>
    +     *
    +     * <p><b>Beware!</b> In most cases you don't want to escape shell
commands but use multi-argument
    +     * methods provided by {@link java.lang.ProcessBuilder} or {@link
java.lang.Runtime#exec(String[])}
    +     * instead.</p>
    +     *
    +     * <p>Example:</p>
    +     * <pre>
    +     * input string: He didn't say, "Stop!"
    +     * output string: He\ didn\'t\ say,\ \"Stop!\"
    +     * </pre>
    +     *
    +     * @see <a href="http://pubs.opengroup.org/onlinepubs/7908799/xcu/
chap2.html">Shell Command Language</a>
    +     * @param input  String to escape values in, may be null
    +     * @return String with escaped values, {@code null} if null string
input
    +     * @since 3.6
    +     */
    +    public static final String escapeXSI(final String input) {
    +        return ESCAPE_XSI.translate(input);
    +    }
    +
    +    /**
    +     * <p>Alias for {@link #escapeXSI(String)}.</p>
    +     *
    +     * @param input String to escape values in, may be null
    +     * @return String with escaped values, {@code null} if null string
input
    +     * @since 3.6
    +     */
    +    public static final String escapeShell(final String input) {
    --- End diff --

    I'm not sure whether it is a good idea to have aliases for methods.
Does this help users to find what they are looking for or does this really
cause confusion?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

[GitHub] commons-lang pull request #208: LANG-1066: Add shell/XSI escape/unescape sup...

Posted by britter <gi...@git.apache.org>.
Github user britter commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/208#discussion_r88777926
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java ---
    @@ -801,4 +876,61 @@ public static final String unescapeCsv(final String input) {
             return UNESCAPE_CSV.translate(input);
         }
     
    +    // Shell
    +    /**
    +     * <p>Escapes the characters in a {@code String} using XSI rules.</p>
    +     *
    +     * <p><b>Beware!</b> In most cases you don't want to escape shell commands but use multi-argument
    +     * methods provided by {@link java.lang.ProcessBuilder} or {@link java.lang.Runtime#exec(String[])}
    +     * instead.</p>
    +     *
    +     * <p>Example:</p>
    +     * <pre>
    +     * input string: He didn't say, "Stop!"
    +     * output string: He\ didn\'t\ say,\ \"Stop!\"
    +     * </pre>
    +     *
    +     * @see <a href="http://pubs.opengroup.org/onlinepubs/7908799/xcu/chap2.html">Shell Command Language</a>
    +     * @param input  String to escape values in, may be null
    +     * @return String with escaped values, {@code null} if null string input
    +     * @since 3.6
    +     */
    +    public static final String escapeXSI(final String input) {
    +        return ESCAPE_XSI.translate(input);
    +    }
    +
    +    /**
    +     * <p>Alias for {@link #escapeXSI(String)}.</p>
    +     *
    +     * @param input String to escape values in, may be null
    +     * @return String with escaped values, {@code null} if null string input
    +     * @since 3.6
    +     */
    +    public static final String escapeShell(final String input) {
    --- End diff --
    
    I'm not sure whether it is a good idea to have aliases for methods. Does this help users to find what they are looking for or does this really cause confusion?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] commons-lang pull request #208: LANG-1066: Add shell/XSI escape/unescape sup...

Posted by britter <gi...@git.apache.org>.
Github user britter commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/208#discussion_r88777893
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java ---
    @@ -413,6 +447,47 @@ public int translate(final CharSequence input, final int index, final Writer out
             }
         }
     
    +    public static final CharSequenceTranslator UNESCAPE_XSI = new BackslashUnescaper();
    +
    +    /**
    +     * Translator object for unescaping backslash escaped entries.
    +     *
    +     * @since 3.6
    +     */
    +    static class BackslashUnescaper extends CharSequenceTranslator {
    --- End diff --
    
    Why not XsiUnescaper?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] commons-lang pull request #208: LANG-1066: Add shell/XSI escape/unescape sup...

Posted by britter <gi...@git.apache.org>.
Github user britter commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/208#discussion_r88777887
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java ---
    @@ -272,6 +272,40 @@ public int translate(final CharSequence input, final int index, final Writer out
             }
         }
     
    +    /**
    +     * Translator object for escaping Shell command language.
    +     *
    +     * @see <a href="http://pubs.opengroup.org/onlinepubs/7908799/xcu/chap2.html">Shell Command Language</a>
    +     */
    +    public static final CharSequenceTranslator ESCAPE_XSI =
    +          new LookupTranslator(
    +            new String[][] {
    +              {"|", "\\|"},
    +              {"&", "\\&"},
    +              {";", "\\;"},
    +              {"<", "\\<"},
    +              {">", "\\>"},
    +              {"(", "\\("},
    +              {")", "\\)"},
    +              {"$", "\\$"},
    +              {"`", "\\`"},
    +              {"\\", "\\\\"},
    +              {"\"", "\\\""},
    +              {"'", "\\'"},
    +              {" ", "\\ "},
    +              {"\t", "\\\t"},
    +              {"\r\n", ""},
    +              {"\n", ""},
    +              {"*", "\\*"},
    +              {"?", "\\?"},
    +              {"[", "\\["},
    --- End diff --
    
    What about the closing braked?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] commons-lang issue #208: LANG-1066: Add shell/XSI escape/unescape support

Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:

    https://github.com/apache/commons-lang/pull/208
  
    
    [![Coverage Status](https://coveralls.io/builds/8675601/badge)](https://coveralls.io/builds/8675601)
    
    Coverage decreased (-0.006%) to 93.549% when pulling **003ce0723989586685333156124fa3fc441dbdd8 on PascalSchumacher:shell_xsi_escape_unescape_support** into **ff4497aff8cc9de4e0b2c6e5e23e5b6550f76f29 on apache:master**.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] commons-lang issue #208: LANG-1066: Add shell/XSI escape/unescape support

Posted by PascalSchumacher <gi...@git.apache.org>.
Github user PascalSchumacher commented on the issue:

    https://github.com/apache/commons-lang/pull/208
  
    As discussed on the mailing list string escaping will move to commons-text, so I'm closing this pull request.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] commons-lang pull request #208: LANG-1066: Add shell/XSI escape/unescape sup...

Posted by PascalSchumacher <gi...@git.apache.org>.
Github user PascalSchumacher commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/208#discussion_r88799453
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringEscapeUtils.java ---
    @@ -272,6 +272,40 @@ public int translate(final CharSequence input, final int index, final Writer out
             }
         }
     
    +    /**
    +     * Translator object for escaping Shell command language.
    +     *
    +     * @see <a href="http://pubs.opengroup.org/onlinepubs/7908799/xcu/chap2.html">Shell Command Language</a>
    +     */
    +    public static final CharSequenceTranslator ESCAPE_XSI =
    +          new LookupTranslator(
    +            new String[][] {
    +              {"|", "\\|"},
    +              {"&", "\\&"},
    +              {";", "\\;"},
    +              {"<", "\\<"},
    +              {">", "\\>"},
    +              {"(", "\\("},
    +              {")", "\\)"},
    +              {"$", "\\$"},
    +              {"`", "\\`"},
    +              {"\\", "\\\\"},
    +              {"\"", "\\\""},
    +              {"'", "\\'"},
    +              {" ", "\\ "},
    +              {"\t", "\\\t"},
    +              {"\r\n", ""},
    +              {"\n", ""},
    +              {"*", "\\*"},
    +              {"?", "\\?"},
    +              {"[", "\\["},
    --- End diff --
    
    according to http://pubs.opengroup.org/onlinepubs/7908799/xcu/chap2.html it does not have to be escaped


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] commons-lang pull request #208: LANG-1066: Add shell/XSI escape/unescape sup...

Posted by PascalSchumacher <gi...@git.apache.org>.
Github user PascalSchumacher closed the pull request at:

    https://github.com/apache/commons-lang/pull/208


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---