OSD600 - Lab 6: Fixing URL bug in Brave browser

In this lab, we are going to fix URL searching bug in Brave browser. Although each browser has its method to handle URL parsing, we hope Brave browser can get the same searching result as those famous browser does. For me, I like Chrome browser the best. So I'm going to fix Brave URL bug to make it have the same result as Chrome does.

Here's the link of our lab: https://wiki.cdot.senecacollege.ca/wiki/OSD600_and_DPS909_Winter_2018_Lab_6

After a few try, we get result from Chrome and Brave. They have different results in some way.


The results are different in URLs which have space inside URL. Then I compare the URL results of them.
Chrome:

Brave:

So I think Brave doesn't replace the space in URL like Chrome does. So Brave separates the URL into 2 parts and search them through searching engine. Our main purpose is to replace it to "%20" in order to let it work in Brave browser.

First we know, Brave already handle the trim function. When Brave get input from address bar, it will remove the space in the front and back. Next step it should do is to replace space inside the input to "%20". But it doesn't do that. That is what we need to fix.

Let's go through the code.

I think the code for handling url is in "urlutil.js" module. When I read the code, I found some functions that may be possible to modify. Like:
 - getUrlFromInput();
I tried adding "input = input.replace(" ", "%20")" right after trim() function in this function, but it doesn't work. I guess the input in this function has been already handled. I put a "console.log" after the trim and see what's the result.

I try "https://www.google.ca/search?q=dog cat" as input to address bar, and I get the result:


The program consider the url is separated as two part: 1. https://www.google.ca/search?q=dog  and 2 cat. Then it uses google as searching engine to produce the result. That's why we see google search bar has content like "https://www.google.ca/search?q=dog cat":


So I need to find the step before this! Before it separated the url with space!

I noticed the isNotUrl function is long. I think this function is to judge if input is an URL or not.

I put a "console.log" after the trim function in "isNotUrl", and send the same url to Brave address bar.
"www.google.ca"
In terminal, I got this result:

I think some of the place in program loop through the original input. It keeps concatenate the input string and check if it is an URL. When it concatenate to "www.google.ca", it checks the string and finds this is the possible URL. Then is call "getUrlFromInput" which I mention before. "getUrlFromInput" will format it as an URL.

Back to our case. I try "https://www.google.ca/search?q=dog cat" as an input, and I got this:

I guess the "isNotUrl" function has already judged it as an url cause it have "https" schema. That's why it doesn't start looping character by character. So it return the url to somewhere else to continue the process. As it doesn't replace the space to "%20", the browser cannot search url with space. The final result for it is, it separates this url as two part and search in Google engine. That's why we see the result search separately in Google website search bar:
So I try replacing space here:

Result:
That's work!

I also try the other three input:
" https://www.google.ca/search?q=dog cat "   -----------------------Fixed!
"/Users/kignorc/brave-browser/browser-laptop/dog cat.txt"-------Fixed!
" /Users/kignorc/brave-browser/browser-laptop/dog cat.txt "------Fixed!

When I push the project to Github, it returns some error! I think I made some other mistake when I just change space to "%20". I refer to the methods of other students, he replace like this:
str.replace(/\s+([^\s]+)/, '%20')

Now I can pass the test!

I write a test to specify test 'isURL' function. This function is opposite to 'isNotURL' function.

This test string should all be URL. It should pass all the tests. I use 'mocha' to run the test, and get the result like this:


Lab done!

Comments

Popular posts from this blog

OSD - Release 03

Studying for open standard