Skip to content

Commit 9145f6b

Browse files
committed
Merge branch 'dev-2.0' into addon-fn-proxy
2 parents 792888c + 57d8b3a commit 9145f6b

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

src/core/internationalization.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import i18next from 'i18next';
22
import LanguageDetector from 'i18next-browser-languagedetector';
33
import { default as fallbackResources, languages } from '../../translations';
4+
import { VERSION } from './constants';
45

56
if (typeof IS_MINIFIED === 'undefined') {
67
// internationalization is only for the unminified build
@@ -147,8 +148,12 @@ export const initialize = () => {
147148
},
148149
backend: {
149150
fallback: 'en',
150-
loadPath:
151-
'https://cdn.jsdelivr.net/npm/p5/translations/{{lng}}/{{ns}}.json'
151+
152+
// ensure that the FES internationalization strings are loaded
153+
// from the latest patch of the current minor version of p5.js
154+
loadPath: `https://cdn.jsdelivr.net/npm/p5@${
155+
VERSION.replace(/^(\d+\.\d+)\.\d+.*$/, '$1')
156+
}/translations/{{lng}}/{{ns}}.json`
152157
},
153158
partialBundledLanguages: true,
154159
resources: fallbackResources

src/type/p5.Font.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,10 +981,17 @@ async function create(pInst, name, path, descriptors, rawFont) {
981981
return new Font(pInst, face, name, path, rawFont);
982982
}
983983

984-
function createFontFace(name, path, descriptors, rawFont) {
985984

986-
if (name.includes(' ')) name = "'" + name + "'"; // NOTE: must be single-quotes
985+
function sanitizeFontName(name) {
986+
if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(name)) {
987+
name = "'" + String(name).replace(/'/g, "\\'") + "'";
988+
}
989+
return name;
990+
}
991+
992+
function createFontFace(name, path, descriptors, rawFont) {
987993

994+
name = sanitizeFontName(name);
988995
let fontArg = rawFont?._compressedData ?? rawFont?._data;
989996
if (!fontArg) {
990997
if (!validFontTypesRe.test(path)) {
@@ -1530,6 +1537,7 @@ export const arrayCommandsToObjects = commands => commands.map(command => {
15301537
}
15311538
});
15321539

1540+
export { sanitizeFontName as _sanitizeFontName };
15331541
export default font;
15341542

15351543
if (typeof p5 !== 'undefined') {

src/webgl/p5.Camera.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,8 +3682,7 @@ function camera(p5, fn){
36823682
};
36833683

36843684
/**
3685-
* Creates a new <a href="#/p5.Camera">p5.Camera</a> object and sets it
3686-
* as the current (active) camera.
3685+
* Creates a new <a href="#/p5.Camera">p5.Camera</a> object.
36873686
*
36883687
* The new camera is initialized with a default position `(0, 0, 800)` and a
36893688
* default perspective projection. Its properties can be controlled with

test/unit/type/p5.Font.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import p5 from '../../../src/app.js';
2+
import {_sanitizeFontName} from '../../../src/type/p5.Font.js';
23

34
suite('p5.Font', function () {
45
var myp5;
@@ -61,3 +62,23 @@ suite('p5.Font', function () {
6162
});
6263
});
6364
});
65+
66+
suite('sanitizeFontName', function () {
67+
test('fully alphabetic or alpha-leading alnum do not need quotes', function () {
68+
assert.equal(_sanitizeFontName('Arial'), 'Arial');
69+
assert.equal(_sanitizeFontName('Family900'), 'Family900');
70+
assert.equal(_sanitizeFontName('A_b-c'), 'A_b-c');
71+
});
72+
73+
test('names starting with a digit need quotes', function () {
74+
assert.equal(_sanitizeFontName('9lives'), "'9lives'");
75+
});
76+
77+
test('names with spaces need quotes', function () {
78+
assert.equal(_sanitizeFontName('My Font'), "'My Font'");
79+
});
80+
81+
test('names with commas need quotes', function () {
82+
assert.equal(_sanitizeFontName('Foo,Bar'), "'Foo,Bar'");
83+
});
84+
});

0 commit comments

Comments
 (0)