David Taylor - Front-End Interface Web Developer

A time to rejoice and a time to grovel

Time to grovel, my gift to dan this morning was to erase all his hard work!! CRAP!!!!

Let me explain, Dan wanted to do a git commit but was confused when the files weren’t appearing in the repository on Github. The reason for this was that he thought that

$ git commit –am “message”

would also add any files that weren’t already in the index and it doesn’t. All it does is add currently tracked files in to the staging area and commit them so you don’t have to run 2 commands.

For any new files you have to run:

$ git add <files>
$ git commit –am “message”

WHAT WENT WRONG

So we did a

$ git add .

Which adds all the untracked files in to the staging area ready to be committed to the repository. Then we realised that there were files in there that we didn’t want to commit.

So in an attempt to move the files out of the staging area I rather stupidly (I blame it on um…kids sleep?? Cogh cogh)

$ git reset --hard 

instead of doing:

$ git reset HEAD *

The rather unwelcome outcome being that all those uncommitted changes were lost!

Needless to say you will find me under my desk grieving the loss I have caused.

SORRY DAN. Beer on me.

Validating Postcodes with a Regular Expression

I have just had an issue where form validation will pass for the following postcode:

ec1r 5ar <script>alert("hi")</script>

The only reason being the fact that there is a valid post code at the beginning. I was using a very slightly adapted regular expression found on the Wikipedia Postcodes article which was:

(GIR 0AA|[A-PR-UWYZ]([0-9][0-9A-HJKPS-UW]?|[A-HK-Y][0-9][0-9ABEHMNPRV-Y]?)[ ]?[0-9][ABD-HJLNP-UW-Z]{2})

So getting my regex hat on. I had the issue that it cannot allow anything after the validated postcode, but also I expect that it would similarly allow junk before the valid postcode. The whole thing is wrapped in matching brackets so all I needed to do was add the begins with (^) and ends with ($) simbols to fix the test with the following regex:

var rege = /^(GIR 0AA|[A-PR-UWYZ]([0-9][0-9A-HJKPS-UW]?|[A-HK-Y][0-9][0-9ABEHMNPRV-Y]?)[ ]?[0-9][ABD-HJLNP-UW-Z]{2})$/i;

console.log(rege.test('ec1r 5ar <script>alert("hi")</script>'))

And this test fails, whoop!