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

  • Home
  • SEARCH
  • 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 1081757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:12:32+00:00 2026-05-16T22:12:32+00:00

Please take a look at the following JavaScript. I’ve taken stuff out of it,

  • 0

Please take a look at the following JavaScript. I’ve taken stuff out of it, so you may focus on the essence of the problem.

You’ll notice that I call the prepPath function twice in a row, passing in the exact same string. In firefox and IE8, this function alerts true each time (as expected). But, in Chromium 5.0.375.127 (55887) Ubuntu 10.04, the function returns true the first time, and false the 2nd call, despite the input remaining exactly the same!

<script type="text/javascript"> 
    function prepPath(str)
    {   
        var regX = /[^\s/"'\\].*[^\s/"'\\]/g;
        if(regX.test(str))
        {
            alert("true: " + str);
        }
        else
        {
            alert("false; " + str);
        }
    }

    prepPath("/desktop"); // alerts: true
    prepPath("/desktop"); // alerts: false 
</script> 

Why is it returning false the second time in Chromium?

  • 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-05-16T22:12:33+00:00Added an answer on May 16, 2026 at 10:12 pm

    There’s some ambiguity in the spec about when literal regexes should get reset (recall that they have state). You can work around this by doing this:

    var regX = new RegExp(/[^\s/"'\\].*[^\s/"'\\]/g);
    

    live example: http://jsbin.com/irate

    or this:

    var regX = /[^\s/"'\\].*[^\s/"'\\]/g;
    regX.lastIndex = 0;
    

    live example: http://jsbin.com/irate/2

    I’m informed by those who’ve looked into it more than I have that it’s not actually an outright bug, but an ambiguity. And it’s not just Chrome, some versions of other browsers have also had a similar problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please take a look at the following fiddle: http://jsfiddle.net/ellenchristine/tty3e/ Note that when you expand
Please take a look at the following snippet from ipython: In [122]: len(netean) Out[122]:
Please take a look at the following .htaccess ErrorDocument 404 /404/ RewriteEngine On RewriteRule
Please take a look here: alt text http://img16.imageshack.us/img16/2810/errrp.jpg Why i got that error when
Please take a look at following code: #include <stdio.h> #include <iostream> using namespace std;
please take a look at the following website: http://www.solidcamxpress.co.uk/ If you look at it
Please take a look at the following code: Public Sub Method(Of TEntity As EntityObject)(ByVal
Please take a look at the following line <TextBox Text="{Binding Price}"/> This Price property
Please can someone take a look at the following image: http://img109.imageshack.us/img109/6885/colouring.png I need to
please take a look at the following snippet: public IEnumerable<T> Query(Expression<Func<T, bool>> filter) {

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.