To fix the bug, I had an idea. It was to add hyphen(-) or underscore ( _ ), or just allow spacing in the path name. I suggested my idea and David was able to reply quickly. He asked me to just try removing the encodeURI() function from the code to see what happens.
Once I removed the function, the hints came out perfectly. The path name did not have %20, when there were spaces in the path name. Surprisingly, it was quick bug to fix. I tested the hints with different characters as well and performed accordingly. I was suggested with other test by David, where I should see if I can publish the project.
This is where everything went down hill for me! It looked perfect on preview even when I tested for different type of images (jpg, png, and gif). But when I try to publish them under localhost, nothing was working. All the images showed up as broken links. I was surprised this was happening and at the same time frustrated. Checked whether my repository was up-to-date as well, and it was.
In the end, David suggested that he wants this issue closed. Mainly because he is rethinking the issue he filed originally and said that it may be correct to encode the path names that has spaces in it.