Skip to content
  • @deckar01 Thank you for the script! 👍

    I looks however as if something goes wrong:

    $ git revert --no-commit aaa9509
    $ coffee --compile spec/javascripts/u2f/register_spec.js.coffee
    $ wc --lines spec/javascripts/u2f/register_spec.js.js 
    67 spec/javascripts/u2f/register_spec.js.js
    
    $ echo '#!/usr/bin/env node' > restore-comments.js
    $ curl https://gitlab.com/deckar01/gitlab-ce/snippets/23250/raw >> restore-comments.js
    $ chmod +x restore-comments.js
    $ npm install source-map
    
    $ coffee --map spec/javascripts/u2f/register_spec.js.coffee
    $ ./restore-comments.js spec/javascripts/u2f/register_spec.js.coffee
    $ wc --lines spec/javascripts/u2f/register_spec.js.js 
    14 spec/javascripts/u2f/register_spec.js.js

    This line seems to be the problem:

    setupButton = this.container.find("#js-setup-u2f-device");
  • Author Owner

    Indeed. It doesn't take into account "#" characters that appear inside strings. The regex in the coffee compile is misleading, because it relies on the string already being tokenized.

  • @deckar01 Not sure if it helps, but this is the pattern that I used:

    const quoteCharacters = `"'`
    let pattern = new RegExp(
        '^(?:' +
        
        quoteCharacters.split('').map(
          (character) => 
          '(?:' + character + '(?:' + // start a string quoted by character
          '\\\\' + character + // match escaped quote
          '|[^' + character + ']' +  // or anything but quote
          ')*' + character + ')' // any number of times until end of the quoted string
        ).join('|') +
        
        '|[^' + quoteCharacters + ']' +
        ')*?' +
        '(#.*)?$'
    )
  • Author Owner

    @winniehell It should be quite a bit more robust now. I got it to the point where is was only creating extra comments, then carved away at the edge cases.

    One thing that totally bit me was declaring the regexes in the main scope. Those stateful sucker exhibit strange behavior when you call exec inside of a nested loop and stop consuming the results before the end of the string. Lesson learned.

0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment