1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-22 00:10:15 +00:00

[fix] Private fields: resolve off-by-one error [2].

This commit is contained in:
hacksalot 2018-01-31 15:22:15 -05:00
parent c6adab7f9e
commit fde2146a0b
No known key found for this signature in database
GPG Key ID: 2F343EC247CA4B06
2 changed files with 23 additions and 2 deletions

View File

@ -79,7 +79,7 @@ Definition of the AbstractResume class.
ignoreList = [];
privateList = [];
includePrivates = (opts != null ? opts["private"] : void 0) == null ? true : opts != null ? opts["private"] : void 0;
scrubbed = traverse(rep).map(function(x) {
scrubbed = traverse(rep).map(function() {
if (!this.isLeaf) {
if (this.node.ignore === true || this.node.ignore === 'true') {
ignoreList.push(this.node);
@ -89,6 +89,11 @@ Definition of the AbstractResume class.
this["delete"]();
}
}
if (_.isArray(this.node)) {
this.after(function() {
this.update(_.compact(this.node));
});
}
});
return {
scrubbed: scrubbed,

View File

@ -65,7 +65,7 @@ class AbstractResume
privateList = []
includePrivates = if not opts?.private? then true else opts?.private
scrubbed = traverse( rep ).map ( x ) ->
scrubbed = traverse( rep ).map () -> # [^1]
if !@isLeaf
if @node.ignore == true || @node.ignore == 'true'
ignoreList.push @node
@ -73,6 +73,10 @@ class AbstractResume
else if (@node.private == true || @node.private == 'true') && !includePrivates
privateList.push @node
@delete()
if _.isArray(@node) # [^2]
@after () ->
@update _.compact this.node
return
return
scrubbed: scrubbed
@ -80,3 +84,15 @@ class AbstractResume
privateList: privateList
module.exports = AbstractResume
# [^1]: As of this writing, the NPM traverse library has a quirk when attempting
# to remove array elements directly using traverse's `this.remove`. See:
#
# https://github.com/substack/js-traverse/issues/48
#
# [^2]: The workaround is to use traverse's 'this.delete' to nullify the value
# first, followed by removal with something like _.compact.
#
# https://github.com/substack/js-traverse/issues/48#issuecomment-142607200
#