We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b478bb2 commit b23989aCopy full SHA for b23989a
apps/stock-price-checker/controllers/stockHandler.js
@@ -12,6 +12,10 @@ const request = require('request');
12
13
function StockHandler() {
14
this.getData = function(stock, callback) {
15
+ if (!isValidStock(stock)) {
16
+ callback('stockData', { error: 'invalid symbol' });
17
+ return;
18
+ }
19
request(
20
`https://stock-price-checker-proxy.freecodecamp.rocks/v1/stock/${stock}/quote`,
21
function(error, response, body) {
@@ -68,4 +72,10 @@ function StockHandler() {
68
72
};
69
73
}
70
74
75
+const validTickerRegExp = /^[a-z]{1,6}$/;
76
+const isValidStock = (stock) => {
77
+ const stockL = stock.toLowerCase().trim();
78
+ validTickerRegExp.test(stockL);
79
+}
80
+
71
81
module.exports = StockHandler;
0 commit comments