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

Sync function editor cannot load a sync function with a string replacement pattern in it #47

OldSneerJaw opened this Issue May 1, 2017 · 1 comment


None yet
2 participants
Copy link

OldSneerJaw commented May 1, 2017

When the Sync Gateway admin UI injects a sync function's contents into its editor view (see compileSyncFunction in syncModel.js), it uses the version of the JavaScript String.replace function that expects the replacement parameter as a string. As noted by the Mozilla Developer Network documentation, this version of the function includes support for special replacement patterns which are overwritten dynamically with a value as described here. If a sync function happens to have one of those replacement patterns in its body, it will "compile" the sync function incorrectly.

For example, if a sync function contained the statement

var fileExtensionsRegex = new RegExp('\\.(' + extensions.join('|') + ')$', 'i');

the admin UI would fail to load it because the character sequence $' appears and, according to the documentation linked earlier, String.replace "Inserts the portion of the string that precedes the matched substring", producing a syntax error. A workaround is to denote the string using double quotes, but a proper solution would be to use a replacement function instead of a replacement string so that the literal value is inserted without interpretation.

For example:

syncWrapper.replace('"syncCodeStringHere"', function() { return codeString; })

This bug first surfaced in synctos as issue #116.


This comment has been minimized.

Copy link

OldSneerJaw commented Apr 6, 2018

I've posted a pull request (#49) that addresses this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment