Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9009191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:07:38+00:00 2026-06-16T02:07:38+00:00

here’s a little web-server function that gets a url and parses it, making sure

  • 0

here’s a little web-server function that gets a url and parses it, making sure that the client is not asking for a resource that’s not under the server’s root folder

function getUrl(url, resourceMap, rootFolder) {
    var path = require('path');
    if (typeof resourceMap[url] !== 'undefined') {
        return (path.join(rootFolder,resourceMap[url]));
    } 
    var absoluteURL = path.join(rootFolder,url);
    console.log("ROOT: "+rootFolder);
    console.log("NEW: "+absoluteURL);
    var regex = new RegExp('^' + rootFolder + '.*')
    if (absoluteURL.match(regex) === null) {
        console.log("FALSE");
        return (false);
    }
    return (absoluteURL);
}

As you can see I make sure that absoluteURL starts with rootFolder by using the regex '^' + rootFolder + '.*'

This worked well on Linux, but in windows it always returns false.

BTW the output is

ROOT: C:\Users\user\workspace
NEW: C:\Users\user\workspace\images\IMG_7102.JPG

So I know that parsing of the url is ok.

Amy ideas why?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:07:39+00:00Added an answer on June 16, 2026 at 2:07 am

    On Windows, the \s in the path become escape characters in the regex.

    You need to regex-escape it:

    rootFolder.replace(/[-[\/{}()*+?.\\^$|]/g, "\\$&")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my situation. I've noticed that code gets harder to maintain when you keep
Here is an object that I'd like to use with ng-repeat, but it's not
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Here is my function: function reCalculate(i) { document.getElementById(Q + i).value = document.getElementById(C + i).value
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.