Skip to content

Commit

Permalink
Issue 86 (#86) correction for js property protection
Browse files Browse the repository at this point in the history
updated min file and tests all worked afterwards with the issue reproduction given in the OP
  • Loading branch information
simis-trey committed Dec 18, 2017
1 parent 3aa874b commit 49e5e8a
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 49 deletions.
11 changes: 9 additions & 2 deletions dist/xapiwrapper.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/example.html
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../dist/xapiwrapper.min.js"></script>
<script type="text/javascript">

function init()
{
{
var stmt = new ADL.XAPIStatement(
new ADL.XAPIStatement.Agent(ADL.XAPIWrapper.hash('mailto:steve.vergenz.ctr@adlnet.gov'), 'Steven Vergenz'),
ADL.verbs.launched,
Expand Down
18 changes: 15 additions & 3 deletions examples/useWrapper.html
Expand Up @@ -16,12 +16,22 @@

<script src="./libs/ace-editor/ace.js"></script>



<!--Min-ified version of the files below-->
<script src="../dist/xapiwrapper.min.js"></script>

<!-- <script src="../lib/cryptojs_v3.1.2.js"></script>
<script src="../src/verbs.js"></script>
<!--Required for the base64 conversion, this is included in the minified wrapper-->
<!--<script src="../lib/cryptojs_v3.1.2.js"></script>-->

<!--Individual source files-->
<!--<script src="../src/verbs.js"></script>
<script src="../src/activitytypes.js"></script>
<script src="../src/xapistatement.js"></script>
<script src="../src/xapi-util.js"></script>
<script src="../src/xapi-launch.js"></script>
<script src="../src/xapiwrapper.js"></script> -->
<script src="../src/xapiwrapper.js"></script>-->

<!-- <script src="../src/offline.js"></script>
<script src="../src/storage.js"></script>
<script src="../src/validator.js"></script> -->
Expand Down Expand Up @@ -359,7 +369,9 @@ <h4>Custom Statement</h4>
};

$('#sendbtn').on('click', function (ev) {

var instmt = JSON.parse(editor.getValue());

if (Array.isArray(instmt)) {
console.log('sending array - multi stmt... ');
wrapper.sendStatements(instmt, outputResults);
Expand Down
9 changes: 6 additions & 3 deletions src/xapi-launch.js
Expand Up @@ -46,11 +46,14 @@ function observeForNewLinks()
{
for (var i in mutation.addedNodes)
{
if (mutation.addedNodes[i].constructor == HTMLAnchorElement)
if (mutation.addedNodes.hasOwnProperty(i))
{
var node = mutation.addedNodes[i];
setupCourseLinks([node]);
if (mutation.addedNodes[i].constructor == HTMLAnchorElement) {
var node = mutation.addedNodes[i];
setupCourseLinks([node]);
}
}

}
});
});
Expand Down
65 changes: 39 additions & 26 deletions src/xapiwrapper.js
Expand Up @@ -72,7 +72,8 @@ function isDate(date) {
}
}

(function(ADL){
(function (ADL) {

log.debug = false;

function getByteLen(normal_val) {
Expand Down Expand Up @@ -107,14 +108,14 @@ function isDate(date) {
{
var conf = {};
conf['endpoint'] = "http://localhost:8000/xapi/";
try
{
//try
//{
conf['auth'] = "Basic " + toBase64('tom:1234');
}
catch (e)
{
log("Exception in Config trying to encode auth: " + e);
}
//}
//catch (e)
//{
// log("Exception in Config trying to encode auth: " + e);
//}

// Statement defaults
// conf["actor"] = {"mbox":"default@example.com"};
Expand Down Expand Up @@ -176,11 +177,12 @@ function isDate(date) {
var versionOK = false;
for (var idx in lrsabout.version)
{
if(lrsabout.version[idx] == ADL.XAPIWrapper.xapiVersion)
{
versionOK = true;
break;
}
if (lrsabout.version.hasOwnProperty(idx))
if(lrsabout.version[idx] == ADL.XAPIWrapper.xapiVersion)
{
versionOK = true;
break;
}
}
if (!versionOK)
{
Expand Down Expand Up @@ -396,9 +398,11 @@ function isDate(date) {

for(var i in attachments)
{

body += CRLF + '--' + boundary + CRLF + 'X-Experience-API-Hash:' + attachments[i].type.sha2 + CRLF + "Content-Type:application/octet-stream" + CRLF + "Content-Transfer-Encoding: binary" + CRLF + CRLF
body += attachments[i].value;
if (attachments.hasOwnProperty(i))
{
body += CRLF + '--' + boundary + CRLF + 'X-Experience-API-Hash:' + attachments[i].type.sha2 + CRLF + "Content-Type:application/octet-stream" + CRLF + "Content-Transfer-Encoding: binary" + CRLF + CRLF
body += attachments[i].value;
}
}
body += CRLF + "--" + boundary + "--" + CRLF

Expand Down Expand Up @@ -437,7 +441,8 @@ function isDate(date) {
{
for(var i in stmtArray)
{
this.prepareStatement(stmtArray[i]);
if (stmtArray.hasOwnProperty(i))
this.prepareStatement(stmtArray[i]);
}
var resp = ADL.XHR_request(this.lrs,this.lrs.endpoint+"statements",
"POST", JSON.stringify(stmtArray), this.lrs.auth, callback, null,
Expand Down Expand Up @@ -488,11 +493,14 @@ function isDate(date) {

for (s in searchparams)
{
if (s == "until" || s == "since") {
var d = new Date(searchparams[s]);
urlparams.push(s + "=" + encodeURIComponent(d.toISOString()));
} else {
urlparams.push(s + "=" + encodeURIComponent(searchparams[s]));
if (searchparams.hasOwnProperty(s))
{
if (s == "until" || s == "since") {
var d = new Date(searchparams[s]);
urlparams.push(s + "=" + encodeURIComponent(d.toISOString()));
} else {
urlparams.push(s + "=" + encodeURIComponent(searchparams[s]));
}
}
}
if (urlparams.length > 0)
Expand Down Expand Up @@ -1220,6 +1228,9 @@ function isDate(date) {
{
for (var p in obj2)
{
if (obj2.hasOwnProperty(p) == false)
continue;

prop = obj2[p];
log(p + " : " + prop);
try
Expand Down Expand Up @@ -1336,8 +1347,9 @@ function isDate(date) {

//Headers
if(headers !== null){
for(var headerName in headers){
formData.push(headerName + "=" + encodeURIComponent(headers[headerName]));
for (var headerName in headers) {
if (headers.hasOwnProperty(headerName))
formData.push(headerName + "=" + encodeURIComponent(headers[headerName]));
}
}

Expand Down Expand Up @@ -1443,8 +1455,9 @@ function isDate(date) {
headers["Authorization"] = auth;
headers['X-Experience-API-Version'] = ADL.XAPIWrapper.xapiVersion;
if(extraHeaders !== null){
for(var headerName in extraHeaders){
headers[headerName] = extraHeaders[headerName];
for (var headerName in extraHeaders) {
if (extraHeaders.hasOwnProperty(headerName))
headers[headerName] = extraHeaders[headerName];
}
}

Expand Down
35 changes: 22 additions & 13 deletions test/my.mock.wrapper.js
Expand Up @@ -139,11 +139,12 @@ function isDate(date) {
var versionOK = false;
for (var idx in lrsabout.version)
{
if(lrsabout.version[idx] == ADL.XAPIWrapper.xapiVersion)
{
versionOK = true;
break;
}
if (lrsabout.version.hasOwnProperty(idx))
if(lrsabout.version[idx] == ADL.XAPIWrapper.xapiVersion)
{
versionOK = true;
break;
}
}
if (!versionOK)
{
Expand Down Expand Up @@ -343,11 +344,14 @@ function isDate(date) {

for (s in searchparams)
{
if (s == "until" || s == "since") {
var d = new Date(searchparams[s]);
urlparams.push(s + "=" + encodeURIComponent(d.toISOString()));
} else {
urlparams.push(s + "=" + encodeURIComponent(searchparams[s]));
if (searchparams.hasOwnProperty(s))
{
if (s == "until" || s == "since") {
var d = new Date(searchparams[s]);
urlparams.push(s + "=" + encodeURIComponent(d.toISOString()));
} else {
urlparams.push(s + "=" + encodeURIComponent(searchparams[s]));
}
}
}
if (urlparams.length > 0)
Expand Down Expand Up @@ -643,6 +647,9 @@ function isDate(date) {
{
for (var p in obj2)
{
if (obj2.hasOwnProperty(p) == false)
continue;

var prop = obj2[p];
log(p + " : " + prop);
try
Expand Down Expand Up @@ -761,8 +768,9 @@ function isDate(date) {

//Headers
if(headers !== null){
for(var headerName in headers){
formData.push(headerName + "=" + encodeURIComponent(headers[headerName]));
for (var headerName in headers) {
if (headers.hasOwnProperty(headerName))
formData.push(headerName + "=" + encodeURIComponent(headers[headerName]));
}
}

Expand Down Expand Up @@ -873,7 +881,8 @@ function isDate(date) {

for (var k in thesekeys)
{
arrstmts.push(ADL.stmts[thesekeys[k]]);
if (thesekeys.hasOwnProperty(k))
arrstmts.push(ADL.stmts[thesekeys[k]]);
}
//assume there's no more statements, if there are more,
//then return the next index number
Expand Down

0 comments on commit 49e5e8a

Please sign in to comment.