Resolved Detection of items with brackets in name fails

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

  1. Aidden

    Aidden The better executive ;)

    Joined:
    Dec 3, 2013
    Messages:
    3,362
    Likes Received:
    677
    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

    SlashnHax The Chosen One

    Joined:
    Dec 10, 2014
    Messages:
    2,932
    Likes Received:
    853
    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 The Developer

    Joined:
    Jul 28, 2013
    Messages:
    2,378
    Likes Received:
    781
    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

    SlashnHax The Chosen One

    Joined:
    Dec 10, 2014
    Messages:
    2,932
    Likes Received:
    853
    What about the closing braces and brackets?
     
  5. Viewer

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

    Aidden The better executive ;)

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

    SlashnHax The Chosen One

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

    Cloud The Developer

    Joined:
    Jul 28, 2013
    Messages:
    2,378
    Likes Received:
    781
    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...