/*
Returns true if the specified URL should be encoded to include
the session id, false if not.
5984
public boolean shouldEncodeURL(String pURL, HttpServletRequest pRequest) {
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
            LoggingUtil.SESSION_LOGGER_CORE.entering(methodClassName, methodNames[SHOULD_ENCODE_URL]);
        }

        // per spec - For example, if the browser supports cookies, or session
        // tracking is turned off, URL encoding is unnecessary.
        // 6.1 and previous releases always encoded the url if it was set ... if a
        // customer wants this functionality, they should set the alwaysEncodeURL
        // property
        if (!SessionManagerConfig.isAlwaysEncodeURL() && _smc.getEnableCookies() && pRequest.getHeader("Cookie") != null) {
            if (SessionManagerConfig.checkSessionCookieNameOnEncodeURL()) {
                Cookie[] cookies = pRequest.getCookies();
                for (int i = 0; i < cookies.length; i++ ) {
                    if (cookies[i].getName().equals(_smc.getSessionCookieName())) {
                        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
                            LoggingUtil.SESSION_LOGGER_CORE.exiting(methodClassName, methodNames[SHOULD_ENCODE_URL], "false - A http session cookie was found");
                        }                                            
                        return false;
                    }
                } 
            } else {            
                if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
                    LoggingUtil.SESSION_LOGGER_CORE.exiting(methodClassName, methodNames[SHOULD_ENCODE_URL], "false - A cookie was found");
                }
                return false;
            }
        }

        if (!_smc.getEnableUrlRewriting()) {
            if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
                LoggingUtil.SESSION_LOGGER_CORE.exiting(methodClassName, methodNames[SHOULD_ENCODE_URL], "false - encodeOff");
            }
            return false;
        }

        if (!isProtocolSwitch(pURL, pRequest)) {
            if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
                LoggingUtil.SESSION_LOGGER_CORE.exiting(methodClassName, methodNames[SHOULD_ENCODE_URL], "true - encodeProtocolSwitchOff");
            }
            return true;
        } else {
            if (_smc.getEnableUrlProtocolSwitchRewriting()) {
                if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
                    LoggingUtil.SESSION_LOGGER_CORE.exiting(methodClassName, methodNames[SHOULD_ENCODE_URL], "true - encodeProtocolSwitchOn");
                }
                return true;
            } else {
                if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
                    LoggingUtil.SESSION_LOGGER_CORE.exiting(methodClassName, methodNames[SHOULD_ENCODE_URL], "false");
                }
                return false;
            }
        }
    }
49336
public String encodeURL(String relativePath, String scheme) {
		return session.encodeURL(relativePath, scheme);
	}
156282
public boolean isRequestedSessionIdFromURL()
    {
        if (WCCustomProperties.CHECK_REQUEST_OBJECT_IN_USE){
            checkRequestObjectInUse();
        }
        // 321485
        boolean idFromURL = ((WebAppDispatcherContext) this.getDispatchContext()).isRequestedSessionIdFromURL();
        if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
            logger.logp(Level.FINE, CLASS_NAME,"isRequestedSessionIdFromURL", " " + String.valueOf(idFromURL));
        }
        // return _connContext.getSessionAPISupport().isRequestedSessionIdFromURL();
        return idFromURL;
    }
1311399
private static String decodeUrl(String url) {
        if (url == null) {
            return null;
        }

        try {
            return URLDecoder.decode(url, CHARSET_UTF8);
        } catch (UnsupportedEncodingException e) {
            return url;
        }
    }
869738
function urlEncode(data) {
  log("==================================================");
  log("Data before urlEncode");
  log("==================================================");
  log(data);

  if (data === "") {
    return data;
  }

  let find = ["~", "%20", "'"];
  let replace = ["%7E", "+", "%27"];
  let encodedData = encodeURIComponent(data);

  find.forEach((encodedChar, index) => {
    let regex = new RegExp(encodedChar, "g");
    encodedData = encodedData.replace(regex, replace[index]);
  });

  log("==================================================");
  log("Data after urlEncode");
  log("==================================================");
  log(encodedData);

  return encodedData;
}
219038
public boolean acceptsURL(String url) {

        if (url == null) {
            return false;
        }

        return url.regionMatches(true, 0, DatabaseURL.S_URL_PREFIX, 0,
                                 DatabaseURL.S_URL_PREFIX.length());
    }
299912
@Override
    public String encodeURL(ServletRequest request, String uri, SessionAffinityContext affinityContext) {
        return encodeURL(null, request, uri, affinityContext);
    }
948238
public function setSessionPostLoginUrl($url)
    {
        $normalized = null;
        if ($url instanceof Page) {
            if (!$url->isError()) {
                $cID = (int) $url->getCollectionID();
                if ($cID > 0) {
                    $normalized = $cID;
                }
            }
        } elseif ($this->valn->integer($url, 1)) {
            $normalized = (int) $url;
        } else {
            $url = (string) $url;
            if (strpos($url, '/') !== false) {
                $normalized = $url;
            }
        }
        $this->resetSessionPostLoginUrl();
        if ($normalized !== null) {
            $this->session->set(static::POSTLOGIN_SESSION_KEY, $normalized);
        }
    }
512299
public static boolean isHttpUrl(String s) {
        String lowerCaseSource = s.toLowerCase();
        return lowerCaseSource.startsWith("https:/") || lowerCaseSource.startsWith("http:/");
    }
1353283
public static String getUrlWithoutSessionId(String url, String sessionIdName) {

        if (isSessionEncodedInUrl(url, sessionIdName)) {
            return url.substring(0, url.indexOf(getSessionIdSubstring(sessionIdName)));
        }
        return url;
    }
1145281
public String encodeURL(String url) {
        StringBuffer urlEncoded = new StringBuffer();
        int indexOfQuestionMark = url.indexOf("?");
        if (indexOfQuestionMark > 0) {
            // Handles those cases :
            // http://forums.searchenginewatch.com/showthread.php?t=9817
            // http://forums.searchenginewatch.com/showthread.php?p=72232#post72232
            String urlBeforeQuestionMark = url.substring(0, indexOfQuestionMark);
            String urlAfterQuestionMark = url.substring(indexOfQuestionMark);
            urlEncoded = urlEncoded.append(urlBeforeQuestionMark);
            urlEncoded = urlEncoded.append(";jsessionid=");
            urlEncoded = urlEncoded.append(httpSession.getId());
            urlEncoded = urlEncoded.append(urlAfterQuestionMark);
        } else {
            // Handles those cases :
            // http://www.seroundtable.com/archives/003204.html#more
            // http://www.seroundtable.com/archives#more
            int indexOfPoundSign = url.indexOf("#");
            if (indexOfPoundSign > 0) {
                String urlBeforePoundSign = url.substring(0, indexOfPoundSign);
                String urlAfterPoundSign = url.substring(indexOfPoundSign);
                urlEncoded = urlEncoded.append(urlBeforePoundSign);
                urlEncoded = urlEncoded.append(";jsessionid=");
                urlEncoded = urlEncoded.append(httpSession.getId());
                urlEncoded = urlEncoded.append(urlAfterPoundSign);
            } else {
                // Handles the rest
                // http://www.seroundtable.com/archives/003204.html
                // http://www.seroundtable.com/archives
                urlEncoded = urlEncoded.append(url);
                urlEncoded = urlEncoded.append(";jsessionid=");
                urlEncoded = urlEncoded.append(httpSession.getId());
            }
        }

        return urlEncoded.toString();
    }
68399
private boolean isForbidden(String uri) {
        String reqUri = uri.toUpperCase();
        reqUri = removeLeadingSlashes(reqUri);

        if (reqUri == null) {
            return false;
        }

        // As per spec (servlet 2.4), deny access to WEB-INF
        if (reqUri.startsWith("WEB-INF/") || reqUri.startsWith("META-INF/"))
            return true;
        else if ((reqUri.equals("WEB-INF") || reqUri.equals("META-INF"))) {
            return true;
        } else {
            return false;
        }
    }
794527
private boolean isSigV2PresignedUrl(URL presignedUrl) {
        String url = presignedUrl.toString();
        return url.contains("AWSAccessKeyId=") && !presignedUrl.toString().contains("X-Amz-Algorithm=AWS4-HMAC-SHA256");
    }
1100731
public static boolean isValidUrl(String url) {
        try {
            if (Strings.isNullOrEmpty(url)) {
                return false;
            }
            new URL(url);
            return true;
        } catch (MalformedURLException e) {
            return false;
        }
    }
1307538
public String urlDecode(String s) {
        if (s == null || s.isEmpty()) {
            return s;
        }
        return URL.decodeQueryString(s);
    }
1217580
function enableInjectionForUrl(url) {
  var url = getCanonicalUrl(url);
  if (activePageMods[url]) {
    return;
  }

  // Enable injection.
  setPagePreference(url, 'enabled', true);

  // Grab current options. Note that if they change we need to re-enable
  // injection to update the pagemod.
  var pagePrefs = getPagePreferences(url);
  var storedOptions = {};
  try {
    storedOptions = JSON.parse(pagePrefs.options);
  } catch (e) {
  }
  // Override defaults with specified values.
  // Except for a few that we don't want to track across session.
  var pageOptions = {
    // The presence of this indicates that the options come from the injector.
    'wtf.injector': true,

    // Larger buffers mean less waste when doing recordings with a large amount
    // of data (like WebGL captures).
    'wtf.trace.session.bufferSize': 6 * 1024 * 1024,

    // This is pretty excessive, but keeps us from truncating WebGL traces.
    // After this limit the file likely won't load due to v8 memory limits
    // anyway.
    'wtf.trace.session.maximumMemoryUsage': 512 * 1024 * 1024,

    // TODO(benvanik): endpoints
    // 'wtf.hud.app.mode': '',
    // 'wtf.hud.app.endpoint': '',

    'wtf.trace.provider.firefoxDebug.present': true,

    // Turn on embed remote images by default.
    // When we have the UI in the extension and can fetch non-origin URLs this
    // won't be required. Note that we allow the page to override this setting.
    'wtf.trace.provider.webgl.embedRemoteImages': true
  };
  for (var key in storedOptions) {
    switch (key) {
      case 'wtf.injector':
      case 'wtf.hud.app.mode':
      case 'wtf.hud.app.endpoint':
      case 'wtf.addons':
      case 'wtf.trace.provider.firefoxDebug.present':
        continue;
    }
    pageOptions[key] = storedOptions[key];
  }

  // Create a page mod for the given URLs.
  var mod = pageMod.PageMod({
    include: [
      url,
      url + '#*'
    ],
    contentScriptFile: self.data.url('content-script.js'),
    contentScriptWhen: 'start',
    contentScriptOptions: {
      // Accessible as self.options in the content script.
      wtfScriptContents: wtfScriptContents,
      wtfOptions: pageOptions
    },
    attachTo: 'top',
    onAttach: function(worker) {
      var injectedTab = new InjectedTab(url, worker);
      injectedTabs.push(injectedTab);
      console.log('added worker for ' + url);

      worker.port.on('page-event', function(data) {
        injectedTab.dispatchEvent(JSON.parse(data));
      });

      worker.on('detach', function() {
        console.log('detached worker for ' + url);
        injectedTab.dispose();
        for (var n = 0; n < injectedTabs.length; n++) {
          if (injectedTabs[n].worker == worker) {
            injectedTabs.splice(n, 1);
            break;
          }
        }

      });
    }
  });
  activePageMods[url] = mod;

  // Find tabs with the URL and reload.
  reloadTabsMatchingUrl(url);
}
1298515
private static final String urlEncode(String s) {
        try {
            return URLEncoder.encode(s, "UTF-8");
        } catch (Exception e) {
            logger.warn("Failed to encode '" + s + "'", e);
            return s;
        }
    }