Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit a2b7a49

Browse files
committed
chore(build): fix version placeholder matching
During the `build` task, the version placeholders will be replaced with the actual values using a RegExp, which expects the placeholders to be surrounded by double quotes. By replacing the quotes from double to single in #15011, the RegExp was not able to match the placeholders. (For reference, the RegExps that match and replace the version placeholders are in [lib/grunt/utils.js][1].) [1]: https://github.com/angular/angular.js/blob/859348c7f61ff5f93b9f81eb7f46842bd018d8e3/lib/grunt/utils.js#L125-L130 Closes #15016
1 parent 31a6ab2 commit a2b7a49

File tree

4 files changed

+73
-8
lines changed

4 files changed

+73
-8
lines changed

lib/grunt/utils.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ module.exports = {
122122

123123
process: function(src, NG_VERSION, strict) {
124124
var processed = src
125-
.replace(/"NG_VERSION_FULL"/g, NG_VERSION.full)
126-
.replace(/"NG_VERSION_MAJOR"/, NG_VERSION.major)
127-
.replace(/"NG_VERSION_MINOR"/, NG_VERSION.minor)
128-
.replace(/"NG_VERSION_DOT"/, NG_VERSION.patch)
129-
.replace(/"NG_VERSION_CDN"/, NG_VERSION.cdn)
130-
.replace(/"NG_VERSION_CODENAME"/, NG_VERSION.codeName);
125+
.replace(/(['"])NG_VERSION_FULL\1/g, NG_VERSION.full)
126+
.replace(/(['"])NG_VERSION_MAJOR\1/, NG_VERSION.major)
127+
.replace(/(['"])NG_VERSION_MINOR\1/, NG_VERSION.minor)
128+
.replace(/(['"])NG_VERSION_DOT\1/, NG_VERSION.patch)
129+
.replace(/(['"])NG_VERSION_CDN\1/, NG_VERSION.cdn)
130+
.replace(/(['"])NG_VERSION_CODENAME\1/, NG_VERSION.codeName);
131131
if (strict !== false) processed = this.singleStrict(processed, '\n\n', true);
132132
return processed;
133133
},

src/AngularPublic.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@
113113
* - `codeName` – `{string}` – Code name of the release, such as "jiggling-armfat".
114114
*/
115115
var version = {
116-
full: '"NG_VERSION_FULL"', // all of these placeholder strings will be replaced by grunt's
117-
major: 'NG_VERSION_MAJOR', // package task
116+
// These placeholder strings will be replaced by grunt's `build` task.
117+
// They need to be double- or single-quoted.
118+
full: '"NG_VERSION_FULL"',
119+
major: 'NG_VERSION_MAJOR',
118120
minor: 'NG_VERSION_MINOR',
119121
dot: 'NG_VERSION_DOT',
120122
codeName: '"NG_VERSION_CODENAME"'

test/e2e/fixtures/version/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<html ng-app>
3+
<body>
4+
<script src="angular.js"></script>
5+
</body>
6+
</html>

test/e2e/tests/version.spec.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
describe('angular.version', function() {
4+
var version;
5+
6+
beforeEach(function() {
7+
loadFixture('version');
8+
version = browser.driver.executeScript('return angular.version');
9+
});
10+
11+
12+
it('should expose the current version as object', function() {
13+
expect(version).toEqual(jasmine.any(Object));
14+
});
15+
16+
it('should contain property `full` (string)', function() {
17+
expect(version.then(get('full'))).toEqual(jasmine.any(String));
18+
});
19+
20+
it('should contain property `major` (number)', function() {
21+
expect(version.then(get('major'))).toEqual(jasmine.any(Number));
22+
});
23+
24+
it('should contain property `minor` (number)', function() {
25+
expect(version.then(get('minor'))).toEqual(jasmine.any(Number));
26+
});
27+
28+
it('should contain property `dot` (number)', function() {
29+
expect(version.then(get('dot'))).toEqual(jasmine.any(Number));
30+
});
31+
32+
it('should contain property `codeName` (string)', function() {
33+
expect(version.then(get('codeName'))).toEqual(jasmine.any(String));
34+
});
35+
36+
it('should not contain "NG_VERSION_" in `codeName`', function() {
37+
expect(version.then(get('codeName'))).not.toMatch(/NG_VERSION_/);
38+
});
39+
40+
it('\'s `full` property should start with `"major.minor.dot"`', function() {
41+
expect(version.then(validate)).toBe(true);
42+
43+
function validate(ver) {
44+
// We test for "starts with", because `full` is not always equal to `"major.minor.dot"`.
45+
// Possible formats: `1.5.8`, `1.5.0-rc.2`, `1.5.9-build.4949`, `1.5.9-local+sha.859348c`
46+
return ver.full.indexOf([ver.major, ver.minor, ver.dot].join('.')) === 0;
47+
}
48+
});
49+
50+
51+
// Helpers
52+
function get(prop) {
53+
return function getter(obj) {
54+
return obj[prop];
55+
};
56+
}
57+
});

0 commit comments

Comments
 (0)