Skip to content

Commit

Permalink
few sanitations
Browse files Browse the repository at this point in the history
  • Loading branch information
subhash-arabhi committed Dec 11, 2024
1 parent c23cc15 commit 71ff662
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ public class NbPacScriptEvaluator implements PacScriptEvaluator {
private static final String PAC_SOCKS5_FFEXT = "SOCKS5"; // Mozilla Firefox extension. Not part of original Netscape spec.
private static final String PAC_HTTP_FFEXT = "HTTP"; // Mozilla Firefox extension. Not part of original Netscape spec.
private static final String PAC_HTTPS_FFEXT = "HTTPS"; // Mozilla Firefox extension. Not part of original Netscape spec.
private static final RequestProcessor requestProcessor = RequestProcessor.getDefault();
private static class RPSingleton { private static final RequestProcessor instance = new RequestProcessor(NbPacScriptEvaluator.class.getName(), Runtime.getRuntime().availableProcessors(), true, false); }
private static RequestProcessor getRequestProcessor() { return RPSingleton.instance; }
private final String pacScriptSource;


Expand Down Expand Up @@ -231,21 +232,22 @@ public List<Proxy> findProxyForURL(URI uri) throws PacValidationException {

int timeout = ProxySettings.getPacScriptTimeout();

if (timeout == -1){
jsResultAnalyzed = executeScriptEngineSafely(uri);
if (timeout <= 0){
jsResultAnalyzed = executeProxyScript(uri);
} else {
Task task = requestProcessor.post(() -> {
resultHolder.set(executeScriptEngineSafely(uri));
Task task = getRequestProcessor().post(() -> {
resultHolder.set(executeProxyScript(uri));
});

try{
if(!task.waitFinished(timeout)){
LOGGER.log(Level.WARNING, "Timeout when executing PAC script function " + scriptEngine.getJsMainFunction().getJsFunctionName());
LOGGER.log(Level.WARNING, "Timeout when executing PAC script function: {0}", scriptEngine.getJsMainFunction().getJsFunctionName());
}
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
LOGGER.log(Level.WARNING, "PAC script execution interrupted: {0}", ex);
} finally {
if (!task.isFinished()) {
// interruptThread is set true for the RequestProcessor so cancel will interrupt without any setting
task.cancel();
}
}
Expand Down Expand Up @@ -278,7 +280,7 @@ public String getPacScriptSource() {
return this.pacScriptSource;
}

private List<Proxy> executeScriptEngineSafely(URI uri) {
private List<Proxy> executeProxyScript(URI uri) {
try{
Object jsResult;
synchronized (scriptEngine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.netbeans.core.ProxySettings;
import static org.netbeans.core.ProxySettings.PAC_SCRIPT_TIMEOUT;
import org.netbeans.core.network.proxy.pac.impl.NbPacScriptEvaluatorFactory;
import org.netbeans.junit.NbModuleSuite;
import org.netbeans.junit.NbTestCase;
import org.openide.util.NbPreferences;

/**
*
Expand Down Expand Up @@ -73,6 +76,9 @@ public static final junit.framework.Test suite() {
@Test
public void testEngine() throws PacParsingException, IOException, URISyntaxException, PacValidationException {
System.out.println("toSemiColonListStr");

NbPreferences.forModule(ProxySettings.class)
.putInt(PAC_SCRIPT_TIMEOUT, 2000);

PacScriptEvaluatorFactory factory = new NbPacScriptEvaluatorFactory();

Expand Down

0 comments on commit 71ff662

Please sign in to comment.