mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-30 10:36:35 +02:00
Merge branch 'release-1.3' of github.com:laurent22/joplin into release-1.3
This commit is contained in:
commit
40380e3066
6
CliClient/package-lock.json
generated
6
CliClient/package-lock.json
generated
@ -2964,9 +2964,9 @@
|
||||
"integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0="
|
||||
},
|
||||
"highlight.js": {
|
||||
"version": "10.1.1",
|
||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.1.1.tgz",
|
||||
"integrity": "sha512-b4L09127uVa+9vkMgPpdUQP78ickGbHEQTWeBrQFTJZ4/n2aihWOGS0ZoUqAwjVmfjhq/C76HRzkqwZhK4sBbg=="
|
||||
"version": "10.2.1",
|
||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.2.1.tgz",
|
||||
"integrity": "sha512-A+sckVPIb9zQTUydC9lpRX1qRFO/N0OKEh0NwIr65ckvWA/oMY8v9P3+kGRK3w2ULSh9E8v5MszXafodQ6039g=="
|
||||
},
|
||||
"homedir-polyfill": {
|
||||
"version": "1.0.3",
|
||||
|
@ -52,7 +52,7 @@
|
||||
"font-awesome-filetypes": "^2.1.0",
|
||||
"form-data": "^2.1.4",
|
||||
"fs-extra": "^5.0.0",
|
||||
"highlight.js": "10.1.1",
|
||||
"highlight.js": "^10.2.1",
|
||||
"html-entities": "^1.2.1",
|
||||
"html-minifier": "^3.5.15",
|
||||
"htmlparser2": "^4.1.0",
|
||||
|
@ -104,4 +104,14 @@ describe('models_BaseItem', function() {
|
||||
|
||||
expect(noteAfter).toEqual(noteBefore);
|
||||
}));
|
||||
|
||||
it('should serialize and unserialize properties that contain new lines', asyncTest(async () => {
|
||||
const note = await Note.save({ title: 'note', source_url: '\nhttps://joplinapp.org/\n' });
|
||||
|
||||
const noteBefore = await Note.load(note.id);
|
||||
const serialized = await Note.serialize(noteBefore);
|
||||
const noteAfter = await Note.unserialize(serialized);
|
||||
|
||||
expect(noteAfter).toEqual(noteBefore);
|
||||
}));
|
||||
});
|
||||
|
6
ElectronClient/package-lock.json
generated
6
ElectronClient/package-lock.json
generated
@ -6770,9 +6770,9 @@
|
||||
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw=="
|
||||
},
|
||||
"highlight.js": {
|
||||
"version": "10.1.1",
|
||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.1.1.tgz",
|
||||
"integrity": "sha512-b4L09127uVa+9vkMgPpdUQP78ickGbHEQTWeBrQFTJZ4/n2aihWOGS0ZoUqAwjVmfjhq/C76HRzkqwZhK4sBbg=="
|
||||
"version": "10.2.1",
|
||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.2.1.tgz",
|
||||
"integrity": "sha512-A+sckVPIb9zQTUydC9lpRX1qRFO/N0OKEh0NwIr65ckvWA/oMY8v9P3+kGRK3w2ULSh9E8v5MszXafodQ6039g=="
|
||||
},
|
||||
"hoist-non-react-statics": {
|
||||
"version": "2.5.0",
|
||||
|
@ -139,7 +139,7 @@
|
||||
"form-data": "^2.3.2",
|
||||
"formatcoords": "^1.1.3",
|
||||
"fs-extra": "^5.0.0",
|
||||
"highlight.js": "^10.1.1",
|
||||
"highlight.js": "^10.2.1",
|
||||
"html-entities": "^1.2.1",
|
||||
"html-minifier": "^4.0.0",
|
||||
"htmlparser2": "^4.1.0",
|
||||
|
@ -474,13 +474,13 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
|
||||
note.latitude = noteAttributes.latitude;
|
||||
note.longitude = noteAttributes.longitude;
|
||||
note.altitude = noteAttributes.altitude;
|
||||
note.author = noteAttributes.author;
|
||||
note.author = noteAttributes.author ? noteAttributes.author.trim() : '';
|
||||
note.is_todo = noteAttributes['reminder-order'] !== '0' && !!noteAttributes['reminder-order'];
|
||||
note.todo_due = dateToTimestamp(noteAttributes['reminder-time'], true);
|
||||
note.todo_completed = dateToTimestamp(noteAttributes['reminder-done-time'], true);
|
||||
note.order = dateToTimestamp(noteAttributes['reminder-order'], true);
|
||||
note.source = noteAttributes.source ? `evernote.${noteAttributes.source}` : 'evernote';
|
||||
note.source_url = noteAttributes['source-url'] ? noteAttributes['source-url'] : '';
|
||||
note.source = noteAttributes.source ? `evernote.${noteAttributes.source.trim()}` : 'evernote';
|
||||
note.source_url = noteAttributes['source-url'] ? noteAttributes['source-url'].trim() : '';
|
||||
|
||||
noteAttributes = null;
|
||||
} else if (n == 'resource') {
|
||||
@ -488,9 +488,9 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
|
||||
id: noteResource.id,
|
||||
dataFilePath: noteResource.dataFilePath,
|
||||
dataEncoding: noteResource.dataEncoding,
|
||||
mime: noteResource.mime,
|
||||
title: noteResource.filename ? noteResource.filename : '',
|
||||
filename: noteResource.filename ? noteResource.filename : '',
|
||||
mime: noteResource.mime ? noteResource.mime.trim() : '',
|
||||
title: noteResource.filename ? noteResource.filename.trim() : '',
|
||||
filename: noteResource.filename ? noteResource.filename.trim() : '',
|
||||
});
|
||||
|
||||
noteResource = null;
|
||||
|
@ -616,9 +616,9 @@
|
||||
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw=="
|
||||
},
|
||||
"highlight.js": {
|
||||
"version": "10.1.1",
|
||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.1.1.tgz",
|
||||
"integrity": "sha512-b4L09127uVa+9vkMgPpdUQP78ickGbHEQTWeBrQFTJZ4/n2aihWOGS0ZoUqAwjVmfjhq/C76HRzkqwZhK4sBbg=="
|
||||
"version": "10.2.1",
|
||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.2.1.tgz",
|
||||
"integrity": "sha512-A+sckVPIb9zQTUydC9lpRX1qRFO/N0OKEh0NwIr65ckvWA/oMY8v9P3+kGRK3w2ULSh9E8v5MszXafodQ6039g=="
|
||||
},
|
||||
"html-entities": {
|
||||
"version": "1.2.1",
|
||||
|
@ -18,7 +18,7 @@
|
||||
"base-64": "^0.1.0",
|
||||
"font-awesome-filetypes": "^2.1.0",
|
||||
"fs-extra": "^8.1.0",
|
||||
"highlight.js": "10.1.1",
|
||||
"highlight.js": "^10.2.1",
|
||||
"html-entities": "^1.2.1",
|
||||
"json-stringify-safe": "^5.0.1",
|
||||
"katex": "^0.12.0",
|
||||
|
@ -256,9 +256,11 @@ class BaseItem extends BaseModel {
|
||||
propValue = JSON.stringify(propValue);
|
||||
} else if (propValue === null || propValue === undefined) {
|
||||
propValue = '';
|
||||
} else {
|
||||
propValue = `${propValue}`;
|
||||
}
|
||||
|
||||
return propValue;
|
||||
return propValue.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
|
||||
}
|
||||
|
||||
static unserialize_format(type, propName, propValue) {
|
||||
@ -279,7 +281,7 @@ class BaseItem extends BaseModel {
|
||||
propValue = Database.formatValue(ItemClass.fieldType(propName), propValue);
|
||||
}
|
||||
|
||||
return propValue;
|
||||
return typeof propValue === 'string' ? propValue.replace(/\\n/g, '\n').replace(/\\r/g, '\r') : propValue;
|
||||
}
|
||||
|
||||
static async serialize(item, shownKeys = null) {
|
||||
|
@ -3,6 +3,7 @@ const { stringify } = require('query-string');
|
||||
const { time } = require('lib/time-utils.js');
|
||||
const Logger = require('lib/Logger').default;
|
||||
const { _ } = require('lib/locale');
|
||||
const urlUtils = require('lib/urlUtils.js');
|
||||
|
||||
class OneDriveApi {
|
||||
// `isPublic` is to tell OneDrive whether the application is a "public" one (Mobile and desktop
|
||||
@ -90,16 +91,16 @@ class OneDriveApi {
|
||||
}
|
||||
|
||||
async execTokenRequest(code, redirectUri) {
|
||||
const body = new shim.FormData();
|
||||
body.append('client_id', this.clientId());
|
||||
if (!this.isPublic()) body.append('client_secret', this.clientSecret());
|
||||
body.append('code', code);
|
||||
body.append('redirect_uri', redirectUri);
|
||||
body.append('grant_type', 'authorization_code');
|
||||
const body = {};
|
||||
body['client_id'] = this.clientId();
|
||||
if (!this.isPublic()) body['client_secret'] = this.clientSecret();
|
||||
body['code'] = code;
|
||||
body['redirect_uri'] = redirectUri;
|
||||
body['grant_type'] = 'authorization_code';
|
||||
|
||||
const r = await shim.fetch(this.tokenBaseUrl(), {
|
||||
method: 'POST',
|
||||
body: body,
|
||||
body: urlUtils.objectToQueryString(body),
|
||||
headers: {
|
||||
['Content-Type']: 'application/x-www-form-urlencoded',
|
||||
},
|
||||
@ -366,19 +367,21 @@ class OneDriveApi {
|
||||
throw new Error(_('Cannot refresh token: authentication data is missing. Starting the synchronisation again may fix the problem.'));
|
||||
}
|
||||
|
||||
const body = new shim.FormData();
|
||||
body.append('client_id', this.clientId());
|
||||
if (!this.isPublic()) body.append('client_secret', this.clientSecret());
|
||||
body.append('refresh_token', this.auth_.refresh_token);
|
||||
body.append('redirect_uri', 'http://localhost:1917');
|
||||
body.append('grant_type', 'refresh_token');
|
||||
const body = {};
|
||||
body['client_id'] = this.clientId();
|
||||
if (!this.isPublic()) body['client_secret'] = this.clientSecret();
|
||||
body['refresh_token'] = this.auth_.refresh_token;
|
||||
body['redirect_uri'] = 'http://localhost:1917';
|
||||
body['grant_type'] = 'refresh_token';
|
||||
|
||||
const options = {
|
||||
const response = await shim.fetch(this.tokenBaseUrl(), {
|
||||
method: 'POST',
|
||||
body: body,
|
||||
};
|
||||
body: urlUtils.objectToQueryString(body),
|
||||
headers: {
|
||||
['Content-Type']: 'application/x-www-form-urlencoded',
|
||||
},
|
||||
});
|
||||
|
||||
const response = await shim.fetch(this.tokenBaseUrl(), options);
|
||||
if (!response.ok) {
|
||||
this.setAuth(null);
|
||||
const msg = await response.text();
|
||||
|
@ -13,6 +13,43 @@ const http = require('http');
|
||||
const https = require('https');
|
||||
const toRelative = require('relative');
|
||||
const timers = require('timers');
|
||||
const zlib = require('zlib');
|
||||
|
||||
function fileExists(filePath) {
|
||||
try {
|
||||
return fs.statSync(filePath).isFile();
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const gunzipFile = function(source, destination) {
|
||||
if (!fileExists(source)) {
|
||||
throw new Error(`No such file: ${source}`);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
// prepare streams
|
||||
const src = fs.createReadStream(source);
|
||||
const dest = fs.createWriteStream(destination);
|
||||
|
||||
// extract the archive
|
||||
src.pipe(zlib.createGunzip()).pipe(dest);
|
||||
|
||||
// callback on extract completion
|
||||
dest.on('close', function() {
|
||||
resolve();
|
||||
});
|
||||
|
||||
src.on('error', () => {
|
||||
reject();
|
||||
});
|
||||
|
||||
dest.on('error', () => {
|
||||
reject();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function shimInit() {
|
||||
shim.fsDriver = () => {
|
||||
@ -365,9 +402,25 @@ function shimInit() {
|
||||
const request = http.request(requestOptions, function(response) {
|
||||
response.pipe(file);
|
||||
|
||||
const isGzipped = response.headers['content-encoding'] === 'gzip';
|
||||
|
||||
file.on('finish', function() {
|
||||
file.close(() => {
|
||||
resolve(makeResponse(response));
|
||||
file.close(async () => {
|
||||
if (isGzipped) {
|
||||
const gzipFilePath = `${filePath}.gzip`;
|
||||
await shim.fsDriver().move(filePath, gzipFilePath);
|
||||
|
||||
try {
|
||||
await gunzipFile(gzipFilePath, filePath);
|
||||
resolve(makeResponse(response));
|
||||
} catch (error) {
|
||||
cleanUpOnError(error);
|
||||
}
|
||||
|
||||
shim.fsDriver().remove(gzipFilePath);
|
||||
} else {
|
||||
resolve(makeResponse(response));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -36,21 +36,31 @@ function shimInit() {
|
||||
};
|
||||
|
||||
shim.fetch = async function(url, options = null) {
|
||||
// The native fetch() throws an uncatable error that crashes the app if calling it with an
|
||||
// invalid URL such as '//.resource' or "http://ocloud. de" so detect if the URL is valid beforehand
|
||||
// and throw a catchable error.
|
||||
// Bug: https://github.com/facebook/react-native/issues/7436
|
||||
// The native fetch() throws an uncatchable error that crashes the
|
||||
// app if calling it with an invalid URL such as '//.resource' or
|
||||
// "http://ocloud. de" so detect if the URL is valid beforehand and
|
||||
// throw a catchable error. Bug:
|
||||
// https://github.com/facebook/react-native/issues/7436
|
||||
const validatedUrl = urlValidator.isUri(url);
|
||||
if (!validatedUrl) throw new Error(`Not a valid URL: ${url}`);
|
||||
|
||||
return shim.fetchWithRetry(() => {
|
||||
// If the request has a body and it's not a GET call, and it doesn't have a Content-Type header
|
||||
// we display a warning, because it could trigger a "Network request failed" error.
|
||||
// If the request has a body and it's not a GET call, and it
|
||||
// doesn't have a Content-Type header we display a warning,
|
||||
// because it could trigger a "Network request failed" error.
|
||||
// https://github.com/facebook/react-native/issues/30176
|
||||
if (options?.body && options?.method && options.method !== 'GET' && !options?.headers?.['Content-Type']) {
|
||||
console.warn('Done a non-GET fetch call without a Content-Type header. It may make the request fail.', url, options);
|
||||
}
|
||||
|
||||
// Among React Native `fetch()` many bugs, one of them is that
|
||||
// it will truncate strings when they contain binary data.
|
||||
// Browser fetch() or Node fetch() work fine but as always RN's
|
||||
// one doesn't. There's no obvious way to fix this so we'll
|
||||
// have to wait if it's eventually fixed upstream. See here for
|
||||
// more info:
|
||||
// https://github.com/laurent22/joplin/issues/3986#issuecomment-718019688
|
||||
|
||||
return fetch(validatedUrl, options);
|
||||
}, options);
|
||||
};
|
||||
|
@ -91,4 +91,18 @@ urlUtils.extractResourceUrls = function(text) {
|
||||
return output;
|
||||
};
|
||||
|
||||
urlUtils.objectToQueryString = function(query) {
|
||||
if (!query) return '';
|
||||
|
||||
let queryString = '';
|
||||
const s = [];
|
||||
for (const k in query) {
|
||||
if (!query.hasOwnProperty(k)) continue;
|
||||
s.push(`${encodeURIComponent(k)}=${encodeURIComponent(query[k])}`);
|
||||
}
|
||||
queryString = s.join('&');
|
||||
|
||||
return queryString;
|
||||
};
|
||||
|
||||
module.exports = urlUtils;
|
||||
|
6
ReactNativeClient/package-lock.json
generated
6
ReactNativeClient/package-lock.json
generated
@ -4425,9 +4425,9 @@
|
||||
}
|
||||
},
|
||||
"highlight.js": {
|
||||
"version": "10.1.1",
|
||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.1.1.tgz",
|
||||
"integrity": "sha512-b4L09127uVa+9vkMgPpdUQP78ickGbHEQTWeBrQFTJZ4/n2aihWOGS0ZoUqAwjVmfjhq/C76HRzkqwZhK4sBbg=="
|
||||
"version": "10.2.1",
|
||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.2.1.tgz",
|
||||
"integrity": "sha512-A+sckVPIb9zQTUydC9lpRX1qRFO/N0OKEh0NwIr65ckvWA/oMY8v9P3+kGRK3w2ULSh9E8v5MszXafodQ6039g=="
|
||||
},
|
||||
"hoist-non-react-statics": {
|
||||
"version": "2.5.5",
|
||||
|
@ -25,7 +25,7 @@
|
||||
"events": "^1.1.1",
|
||||
"font-awesome-filetypes": "^2.1.0",
|
||||
"form-data": "^2.1.4",
|
||||
"highlight.js": "10.1.1",
|
||||
"highlight.js": "^10.2.1",
|
||||
"html-entities": "^1.2.1",
|
||||
"htmlparser2": "^4.1.0",
|
||||
"immer": "^7.0.9",
|
||||
|
Loading…
Reference in New Issue
Block a user