URL and regex filtering

I’ll need to check the code because I’m not sure what happens if we have both a URL requirement and a regex specified.

I suspect that when the URL requirement is there, it’s overriding the regex.

Yes, the way I’ve written it, if it matches a URL in the text, that wipes out the result of the regex.

I don’t think that is the correct behaviour, so I’ll make a note to alter this for the next version. The way you expected it worked is how I would expect it should work, too.

(Actual PopClip code below in case of any vague interest…)

    if (![PopActionFlags checkRequirements:self.requirements forEvent:event options:options]) return NO;
    if (![PopActionFlags checkRequiredApps:self.requiredApps andExcludedApps:self.excludedApps forEvent:event]) return NO;
    
    // clear match from previous invocation
    [self clearMatch];
    
    // match the regex, if provided
    NSString *const text=event.selectedText.length>0?event.selectedText:@"";
    if (self.jsRegex) {
        self.jsRegex[@"lastIndex"]=0;
        JSValue *const jsRegexResult=[self.jsRegex invokeMethod:@"exec" withArguments:@[text]];
        self.jsRegex[@"lastIndex"]=0;
        if (jsRegexResult.isArray) {
            _regexResult=jsRegexResult;
            _matchedText=jsRegexResult[0].toString;
        }
    }
    else if (self.nativeRegex) {
        NSArray *captureComponents=[text nm_captureComponentsMatchedByRegex:self.nativeRegex];
        _matchedText=[captureComponents safeFirstObject];
        _regexResult=captureComponents;
    }
    else {
        _matchedText=text;
    }
    
    // check those requirements which act like regexes
    if ([self.requirements containsObject:@"httpurl"]||[self.requirements containsObject:@"url"]) {
        _matchedText=[[event.intel.urls safeFirstObject] absoluteString];
    }
    else if ([self.requirements containsObject:@"email"]) {
        _matchedText=[event.intel.emails safeFirstObject];
    }
    else if ([self.requirements containsObject:@"path"]) {
        _matchedText=[event.intel.paths safeFirstObject];
    }
    return self.matchedText!=nil;
2 Likes