Uploaded image for project: 'Commons Text'
  1. Commons Text
  2. TEXT-149

StringEscapeUtils.unescapeCsv doesn't remove quotes at begin and end of string

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.6
    • 1.9
    • None

    Description

      org.apache.commons.text.translate.CsvTranslators:

      void translateWhole(CharSequence input, Writer out) throws IOException {
          if (input.charAt(0) == '"' && input.charAt(input.length() - 1) == '"') {
              String quoteless = input.subSequence(1, input.length() - 1).toString();
              if (StringUtils.containsAny(quoteless, CsvTranslators.CSV_SEARCH_CHARS)) {
                  out.write(StringUtils.replace(quoteless, CsvTranslators.CSV_ESCAPED_QUOTE_STR, CsvTranslators.CSV_QUOTE_STR));
              } else {
                  out.write(input.toString());
              }
      
          } else {
              out.write(input.toString());
          }
      }

       

      In my opinion first occurence "out.write(input.toString());" should be replaced with:

      out.write(quoteless.toString());

      Because '"' quotes around "input" will be never removed.

      Attachments

        Issue Links

          Activity

            People

              kinow Bruno P. Kinoshita
              kasopey Krzysztof Szalast
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m