Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
cc985a40
Unverified
Commit
cc985a40
authored
5 years ago
by
Muhammad Zaid Bamber
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #20793 from edx/zaid-prod-250
Fixed CDN urls to Static urls on edit.
parents
af50c3c0
d3b1fd24
No related branches found
Branches containing commit
Tags
release-2020-11-02-12.26
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cms/static/js/views/course_info_helper.js
+1
-0
1 addition, 0 deletions
cms/static/js/views/course_info_helper.js
common/static/js/spec/utility_spec.js
+22
-0
22 additions, 0 deletions
common/static/js/spec/utility_spec.js
common/static/js/src/utility.js
+8
-0
8 additions, 0 deletions
common/static/js/src/utility.js
with
31 additions
and
0 deletions
cms/static/js/views/course_info_helper.js
+
1
−
0
View file @
cc985a40
...
...
@@ -2,6 +2,7 @@ define(['codemirror', 'js/utils/handle_iframe_binding', 'utility'],
function
(
CodeMirror
,
IframeBinding
)
{
var
editWithCodeMirror
=
function
(
model
,
contentName
,
baseAssetUrl
,
textArea
)
{
var
content
=
rewriteStaticLinks
(
model
.
get
(
contentName
),
baseAssetUrl
,
'
/static/
'
);
content
=
rewriteCdnLinksToStatic
(
content
);
// eslint-disable-line no-undef
model
.
set
(
contentName
,
content
);
var
$codeMirror
=
CodeMirror
.
fromTextArea
(
textArea
,
{
mode
:
'
text/html
'
,
...
...
This diff is collapsed.
Click to expand it.
common/static/js/spec/utility_spec.js
+
22
−
0
View file @
cc985a40
...
...
@@ -16,3 +16,25 @@ describe('utility.rewriteStaticLinks', function() {
).
toBe
(
'
<img src="http://www.mysite.org/static/foo.x"/>
'
);
});
});
describe
(
'
utility.rewriteCdnLinksToStatic
'
,
function
()
{
'
use strict
'
;
it
(
'
does not replace "url" to "static url" if url is not following "cdn url" pattern
'
,
function
()
{
expect
(
rewriteCdnLinksToStatic
(
// eslint-disable-line no-undef
'
<img src="/asset-v1:UCentralLah+Cs201+2019_1+type@asset+block/foo.x"/>
'
)
).
toBe
(
'
<img src="/asset-v1:UCentralLah+Cs201+2019_1+type@asset+block/foo.x"/>
'
);
expect
(
rewriteCdnLinksToStatic
(
'
<img src="/assets/foo.x"/>
'
)
// eslint-disable-line no-undef
).
toBe
(
'
<img src="/assets/foo.x"/>
'
);
});
it
(
'
does a replace of "cdn url" to "static url" if url is part of absolute url
'
,
function
()
{
expect
(
rewriteCdnLinksToStatic
(
// eslint-disable-line no-undef
'
<img src="//prod-edxapp.edx-cdn.org/assets/foo.x"/>
'
)
).
toBe
(
'
<img src="/static/foo.x"/>
'
);
expect
(
rewriteCdnLinksToStatic
(
// eslint-disable-line no-undef
'
<img src="https://prod-edxapp.edx-cdn.org/assets/foo.x"/>
'
)
).
toBe
(
'
<img src="/static/foo.x"/>
'
);
});
});
This diff is collapsed.
Click to expand it.
common/static/js/src/utility.js
+
8
−
0
View file @
cc985a40
...
...
@@ -35,5 +35,13 @@ window.rewriteStaticLinks = function(content, from, to) {
// escape all regex interpretable chars
fromRe
=
from
.
replace
(
/
[
-
\/\\
^$*+?.()|[
\]
{}
]
/g
,
'
\\
$&
'
);
var
regex
=
new
RegExp
(
'
(https?:
\
/
\
/(www
\
.)?[-a-zA-Z0-9@:%._
\
+~#=]{2,256}
\
.[a-z]{2,6}([-a-zA-Z0-9@:%_
\
+.~#?&//=]*))?
'
+
fromRe
,
'
g
'
);
return
content
.
replace
(
regex
,
replacer
);
};
// Utility method for replacing absolute URLs
window
.
rewriteCdnLinksToStatic
=
function
(
content
)
{
'
use strict
'
;
var
regex
=
new
RegExp
(
'
((https?:)?[/][/](www.)?[-a-zA-Z0-9@:%._+~#=]{2,256}[a-z]{2,6}([-a-zA-Z0-9@:%_+~#?&//=]*)|[a-z-]{14})[/]
'
,
'
g
'
);
// eslint-disable-line max-len
return
content
.
replace
(
regex
,
'
/static/
'
);
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment