From 44066d8c065a07422b6ca6d7927a900982574fe2 Mon Sep 17 00:00:00 2001 From: Rajeswari Krishnakumar Date: Fri, 4 Nov 2016 11:20:32 +0530 Subject: [PATCH] Raji/manu: Fix the bug in validating sheet IDs --- src/util/sheetValidator.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/util/sheetValidator.js b/src/util/sheetValidator.js index 37f2b3d3e..6f860d669 100644 --- a/src/util/sheetValidator.js +++ b/src/util/sheetValidator.js @@ -1,17 +1,24 @@ const SheetNotFoundError = require('../../src/exceptions/sheetNotFoundError'); const ExceptionMessages = require('./exceptionMessages'); -const SheetValidator = function (sheetId) { +const SheetValidator = function (sheetReference) { var self = {}; self.verifySheet = function () { - var sheetUrl = ''; - if (sheetId.trim().startsWith("http")) { - sheetUrl = sheetId; + var sheetId = ''; + if (sheetReference.trim().startsWith("http")) { + var result = sheetReference.match("d\\/(.*?)\\/pubhtml"); + if(result === null) { + throw new SheetNotFoundError(ExceptionMessages.SHEET_NOT_FOUND); + } + sheetId = result[1]; + } else { - sheetUrl = "https://spreadsheets.google.com/feeds/worksheets/" + sheetId + "/public/basic?alt=json"; + sheetId = sheetReference; } + var sheetUrl = "https://spreadsheets.google.com/feeds/worksheets/" + sheetId + "/public/basic?alt=json"; + var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", sheetUrl, false); xmlhttp.withCredentials = false;