Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sailthru script fix, and updates #34

Merged
merged 2 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions add-sailthru-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@
* pattern was removed, it removes the corresponding encoded pattern.
*/

const fs = require("fs")
const fs = require('fs')

const filename = "apple-app-site-association.json"
const filename = 'apple-app-site-association.json'

function updateFile(block) {
const json = JSON.parse(fs.readFileSync(filename, { encoding: "utf8" }))
const json = JSON.parse(fs.readFileSync(filename, { encoding: 'utf8' }))
block(json)
fs.writeFileSync(filename, JSON.stringify(json, null, 2) + "\n", {
encoding: "utf8"
fs.writeFileSync(filename, JSON.stringify(json, null, 2) + '\n', {
encoding: 'utf8'
})
}

function unencodedPatterns(patterns) {
return patterns.filter(pattern => pattern.includes("/"))
return patterns.filter(pattern => pattern.includes('/'))
}

function encodePath(path) {
return path
.split("*")
.split('*')
.filter(component => component.length)
.map(component => new Buffer(component).toString("base64"))
.join("*")
.map(component => new Buffer(component).toString('base64'))
.join('*')
}

function isNotSailthruPattern(pattern) {
Expand All @@ -47,7 +47,7 @@ function isNotSailthruPattern(pattern) {
*/
function encodePattern(pattern) {
const path = pattern.match(/^NOT (.+)$/)[1]
const encoded = encodePath(path.slice(0, -(path.length % 3)))
const encoded = encodePath(path.slice(0, path.length - (path.length % 3)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix. The docs for slice() describe how it works when the argument is negative – it's a shorthand for what I've written out here. The bug was that, if path.length is exactly a multiple of 3, then -(path.length % 3) evaluates to -0, and slice() returns "".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a hell of a bugfix @ashfurrow 👍

return `NOT *${encoded}*`
}

Expand All @@ -58,6 +58,6 @@ updateFile(json => {
...patterns.concat(
patterns.filter(isNotSailthruPattern).map(encodePattern)
),
"*"
'*'
]
})
9 changes: 9 additions & 0 deletions apple-app-site-association.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,28 @@
"NOT /venice-biennale*",
"NOT /gender-equality*",
"NOT /collections",
"NOT /log_in",
"NOT /sign_up",
"NOT /click/*/aHR0cHM6Ly9pdHVuZXMuYXBwbGUuY29tL3VzL3BvZGNhc3QvYXJ0c3kv*",
"NOT /click/*/aHR0cHM6Ly9hcnRzeS5uZXQv*",
"NOT /click/*/aHR0cHM6Ly9hcnRzeS50eXBlZm9ybS5j*",
"NOT /click/*/aHR0cHM6Ly9hcHAuYWRqdXN0LmNv*",
"NOT /users/auth/facebook/callback*",
"NOT /identity-verification*",
"NOT *L2FydGljbGVz*",
"NOT *L2FydGljbGUv*",
"NOT *L3Nlcmllcy8=*",
"NOT *L3ZpZGVv*",
"NOT *L25l*",
"NOT *L25ld3Mv*",
"NOT *L2VkaXRvcmlhbC8=*",
"NOT *LzIwMTYteWVhci1pbi1h*",
"NOT *L3ZlbmljZS1iaWVubmFs*",
"NOT *L2dlbmRlci1lcXVhbGl0*",
"NOT *L2NvbGxlY3Rpb25z*",
"NOT *L2xvZ19p*",
"NOT *L3NpZ25f*",
"NOT *L3VzZXJzL2F1dGgvZmFjZWJvb2svY2FsbGJhY2s=*",
"NOT *L2lkZW50aXR5LXZlcmlmaWNhdGlv*",
"*"
]
Expand Down