1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Resolved Detection of items with brackets in name fails

Discussion in 'Client & Site Support' started by Aidden, Jan 19, 2015.

  1. Aidden

    Aidden Author of MaxiBots

    Joined:
    Dec 3, 2013
    Messages:
    6,600
    Likes Received:
    990
    Inventory.newQuery().names("Guam potion (unf)").results().first() returns null
    Inventory.newQuery().names("Guam potion \\(unf\\)").results().first() finds the correct item

    @Cloud
     
  2. SlashnHax

    Joined:
    Dec 10, 2014
    Messages:
    3,212
    Likes Received:
    1,042
    Seems like the names(String...) is converting the Strings to Patterns but doesn't escape the brackets :/

    Edit: Which means this might be occurring in the other queries as well
     
  3. Cloud

    Cloud Engineer

    Joined:
    Jul 28, 2013
    Messages:
    2,777
    Likes Received:
    1,124
    For the next release, does this check out to you?
    Code (Text):
    1.  
    2. public static Pattern getPatternForExactString(final String string) {
    3. String pattern = "^";
    4. for (char c : string.toCharArray()) {
    5. if (c == '(' || c == ')' || c == '^' || c == '$'|| c == '.' || c == '*' || c == '?' || c == '|'|| c == '[' || c == '{') {
    6. pattern += "\\";
    7. }
    8. pattern += c;
    9. }
    10. pattern += "$";
    11. return Pattern.compile(pattern);
    12. }
    13.  
     
  4. SlashnHax

    Joined:
    Dec 10, 2014
    Messages:
    3,212
    Likes Received:
    1,042
    What about the closing braces and brackets?
     
  5. Viewer

    Viewer Discretion is advised

    Joined:
    Jan 2, 2014
    Messages:
    306
    Likes Received:
    77
    You could use IDs instead of names anyway since SpriteItem IDs dont change
     
  6. Aidden

    Aidden Author of MaxiBots

    Joined:
    Dec 3, 2013
    Messages:
    6,600
    Likes Received:
    990
    While that's true, it's could cause problems in other areas.
     
  7. SlashnHax

    Joined:
    Dec 10, 2014
    Messages:
    3,212
    Likes Received:
    1,042
    Plus you'd have to gather all of the IDs, which would be a drag :p
     
  8. Cloud

    Cloud Engineer

    Joined:
    Jul 28, 2013
    Messages:
    2,777
    Likes Received:
    1,124
    From my research, those only need to be escaped when the prior opening isn't escaped.
    Yeah, but I really don't recommend that.
     

Share This Page

Loading...