Chemistry
  1. Chemistry
  2. CMIS-498

Aphostrophes in hard coded string literals are removed in org.apache.chemistry.opencmis.client.runtime.QueryStatementImpl

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: OpenCMIS 0.6.0
    • Fix Version/s: OpenCMIS 0.7.0
    • Component/s: opencmis-client
    • Labels:
    • Environment:

      Ubuntu 11.04 64bit OpenJDK Runtime Environment (IcedTea6 1.10.4) (6b22-1.10.4-0ubuntu1~11.04.2)

      Description

      Aphostrophes in hard coded string literals are removed.

      A simple query without parameters will not work:

      QueryStatement st = session.createQueryStatement("select * from cmis:document where cmis:createdBy = \'admin\'");
      System.out.println(st.toQueryString());
      

      prints out

      select * from cmis:document where cmis:createdBy = admin

      instead of

      select * from cmis:document where cmis:createdBy = 'admin'

      obvious is that this query will not work when sent to a cmis server.

      For my opinion the code of the toQueryString method should be something like this:

          public static String toQueryString() {
              boolean inStr = false;
              int parameterIndex = 0;
      
              StringBuilder sb = new StringBuilder();
              for (int i = 0; i < statement.length(); i++) {
                  char c = statement.charAt(i);
      
                  if (c == '\'') {
                      if (inStr && statement.charAt(i - 1) == '\\') {
                          inStr = true;
                      } else {
                          inStr = !inStr;
                      }
                      sb.append(c);                 // without this line all ' are removed!
                  } else if (c == '?' && !inStr) {  // added && !inStr to have ? in string literals
                      parameterIndex++;
                      String s = parametersMap.get(parameterIndex);
                      if (s == null) {
                          sb.append(c);
                      } else {
                          sb.append(s);
                      }
                  } else {
                      sb.append(c);
                  }
              }
      
              return sb.toString();
          }
      

        Activity

        Bojan Nemec created issue -
        Florian Müller made changes -
        Field Original Value New Value
        Assignee Florian Müller [ fmui ]
        Florian Müller made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s OpenCMIS 0.7.0 [ 12319189 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Florian Müller
            Reporter:
            Bojan Nemec
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development