Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29371130
  
    --- Diff: bin/medic.js ---
    @@ -55,6 +181,210 @@ function exclusiveLs(lsPath, excludes) {
         });
     }
     
    +function getConfigPath(appPath) {
    +    return path.join(appPath, "config.xml");
    +}
    +
    +function getCSPPath(appPath) {
    +    return path.join(appPath, "www", "csp-incl.js");
    +}
    +
    +function addURIToWhitelist(appPath, uri) {
    +
    +    var configFile = getConfigPath(appPath);
    +    var cspFile    = getCSPPath(appPath);
    +
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +    var cspContent    = fs.readFileSync(cspFile, DEFAULT_ENCODING);
    +
    +    // add whitelisting rule allow access to couch server
    +    medicLog("Adding whitelist rule for CouchDB host: " + uri);
    +    var accessOriginTag = "<access origin=\"" + uri + "\" />";
    +    if (!contains(configContent, accessOriginTag)) {
    +        configContent = configContent.split("</widget>").join("");
    +        configContent += "    " + accessOriginTag + "\n</widget>\n";
    +        fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +    }
    +
    +    // add couchdb address to csp rules
    +    medicLog("Adding CSP rule for CouchDB host: " + uri);
    +    var cspRule = "connect-src " + uri;
    +    if (!contains(cspContent, cspRule)) {
    +        cspContent = cspContent.replace("connect-src", cspRule);
    +        fs.writeFileSync(cspFile, cspContent, DEFAULT_ENCODING);
    +    }
    +}
    +
    +function setEntryPoint(appPath, entryPoint) {
    +
    +    var configFile = getConfigPath(appPath);
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +
    +    // replace/add start page preference
    +    // check if config.xml already contains <content /> element
    +    medicLog("Setting entry point to " + entryPoint + " in config.xml");
    +
    +    if (configContent.match(/<content\s*src=".*"\s*\/>/gi)) {
    +        configContent = configContent.replace(
    +            /<content\s*src=".*"\s*\/>/gi,
    +            "<content src=\"" + entryPoint + "\" />"
    +        );
    +
    +    } else {
    +
    +        // add entry point to config
    +        configContent = configContent.split("</widget>").join("") +
    +            "    <content src=\"" + entryPoint + "\" />\n</widget>";
    +    }
    +
    +    // write the changes
    +    fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +}
    +
    +function changeLoadTimeout(appPath, timeout) {
    +
    +    medicLog("Increasing url loading timeout for android to " + timeout);
    +
    +    var timeoutRegex           = /<preference\s*name\s *= 
\s*"?loadUrlTimeoutValue"?.*?((\/>)|(>.*?<\/\s*preference>))/i;
    --- End diff --
    
    Searching SGML-type languages with regex is gross.  Did you consider using 
a lib like ElementTree instead?  That would probably make your code a lot 
cleaner, to find elements via xpath.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org
For additional commands, e-mail: dev-h...@cordova.apache.org

Reply via email to