OSD600 – Lab6

For this lab, we are to fix a bug in the brave browser. The bug is an issue with URL parsing, in particular, when the user enters a space within the search bar.

Some example is:

https://www.google.ca/search?q=dog cat

 https://www.google.ca/search?q=dog cat

When the user tries to enter something similar to the one above the user will get this screen.

As you see above, it enters the URL and uses it to do a google search. Upon first thought, it seems that Brave somehow interpret the whole URL link as a string. Likely we know where this bug is most likely hiding. The place we check was a file called urlutil.js. As we scroll down the Javascript file we found something very interesting. There’s a function that is called isNotURL.

Now to see if the cause of the bug is from here we put some breakpoints on a certain part of the program that we think might have caused the bug to occur. After running the program in debug mode the bug seems to have happened when the program reads this line here.

This line here checks if the string that was sent in and see if it an URL or not. So what seems to have happened is that the space that was entered in between the dog and cat it will cause Brave to think that the URL entered above is actually a string. The reason why it thinks its a string over a URL is mainly that Brave does not read a space as the code %20 causing the URL not to work. So to fix this problem all we really need to do is to replace that space with a %20. Luckily for us, the URL that was passed in was a string so we could do the following to fix it.

And last but not least, we need to write a test to make sure this hasn’t broken anything else in the program. The test for urlutil.js is in a file called urlutilTest.js. In the test, we can find similar tests in it so all we have to do is added our part to the test to see if what we fixed will work with the pre-existing part.

We will now try to run this test to see if it works.

In our first terminal, we enter the following to ensure everything works:

npm run watch-test

Next, we will type the following in a different terminal. We will use a grep to find the certain test so that we will not have to sit through the whole testing process.

npm run test -- --grep="getUrlFromInput"

It seems that our test has gone through successfully and did not break anything which good.

As you see above the space in between dog and cat has been replaced with a %20, and this will also fix the same problem with files. Below will you can see that it also fixes the bug within the file read part.

In conclusion, the bug that we fix was certainly interesting. I was able to learn more about how Brave deals with the URL that got passed in.

 

Leave a comment