lib/assets/javascripts/unpoly/classes/url_set.coffee in unpoly-rails-0.57.0 vs lib/assets/javascripts/unpoly/classes/url_set.coffee in unpoly-rails-0.60.0

- old
+ new

@@ -6,22 +6,27 @@ @normalizeUrl = options.normalizeUrl || u.normalizeUrl @urls = u.map(@urls, @normalizeUrl) @urls = u.compact(@urls) matches: (testUrl) => - if testUrl.substr(-1) == '*' - @doesMatchPrefix(testUrl.slice(0, -1)) + if testUrl.indexOf('*') >= 0 + @doesMatchPattern(testUrl) else @doesMatchFully(testUrl) doesMatchFully: (testUrl) => u.contains(@urls, testUrl) - doesMatchPrefix: (prefix) => - u.detect @urls, (url) -> - url.indexOf(prefix) == 0 + doesMatchPattern: (pattern) => + placeholder = "__ASTERISK__" + pattern = pattern.replace(/\*/g, placeholder) + pattern = u.escapeRegexp(pattern) + pattern = pattern.replace(new RegExp(placeholder, 'g'), '.*?') + pattern = new RegExp('^' + pattern + '$') + u.find @urls, (url) -> pattern.test(url) + matchesAny: (testUrls) => - u.detect(testUrls, @matches) + u.find(testUrls, @matches) - isEqual: (otherSet) => + "#{u.isEqual.key}": (otherSet) => u.isEqual(@urls, otherSet?.urls)