Skip to content

Commit

Permalink
Merge pull request #1772 from fastn-stack/asset-path-fix
Browse files Browse the repository at this point in the history
fix: global object nested path conflict when assets begin with same name
  • Loading branch information
amitu authored Feb 16, 2024
2 parents 36b9089 + 814621a commit cdda10c
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4803,7 +4803,6 @@ const ftd = (function () {
return;
}


if (body && method !== "GET") {
if (body[0] instanceof fastn.recordInstanceClass) {
if (body.length !== 1) {
Expand Down
2 changes: 1 addition & 1 deletion fastn-core/tests/08-static-assets/output/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4803,7 +4803,6 @@ const ftd = (function () {
return;
}


if (body && method !== "GET") {
if (body[0] instanceof fastn.recordInstanceClass) {
if (body.length !== 1) {
Expand Down
2 changes: 1 addition & 1 deletion fastn-core/tests/09-markdown-pages/output/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4803,7 +4803,6 @@ const ftd = (function () {
return;
}


if (body && method !== "GET") {
if (body[0] instanceof fastn.recordInstanceClass) {
if (body.length !== 1) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion fastn-core/tests/17-sitemap/output/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion fastn-core/tests/17-sitemap/output/install/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4803,7 +4803,6 @@ const ftd = (function () {
return;
}


if (body && method !== "GET") {
if (body[0] instanceof fastn.recordInstanceClass) {
if (body.length !== 1) {
Expand Down
38 changes: 19 additions & 19 deletions fastn-core/tests/19-offline-build/output/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4803,7 +4803,6 @@ const ftd = (function () {
return;
}


if (body && method !== "GET") {
if (body[0] instanceof fastn.recordInstanceClass) {
if (body.length !== 1) {
Expand Down
2 changes: 1 addition & 1 deletion fastn-core/tests/21-http-endpoint/output/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion fastn-js/src/to_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ impl fastn_js::SetProperty {
.append(text(
format!(
"{},",
self.value
&self
.value
.to_js_with_element_name(&Some(self.element_name.clone()))
)
.as_str(),
Expand Down Expand Up @@ -677,6 +678,11 @@ fn variable_to_js(
let (doc_name, remaining) = fastn_js::utils::get_doc_name_and_remaining(variable_name);
let mut name = fastn_js::utils::name_to_js(doc_name.as_str());
if let Some(remaining) = remaining {
let remaining = if fastn_js::utils::is_asset_path(doc_name.as_str()) {
remaining.replace('.', "_")
} else {
remaining
};
name = format!(
"{}.{}",
name,
Expand Down
19 changes: 18 additions & 1 deletion fastn-js/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ pub fn is_kernel(s: &str) -> bool {

pub fn reference_to_js(s: &str) -> String {
let (prefix, s) = get_prefix(s);
let (mut p1, mut p2) = get_doc_name_and_remaining(s.as_str());
let (mut p1, p2) = get_doc_name_and_remaining(s.as_str());
let mut p2 = if is_asset_path(p1.as_str()) {
p2.map(|s| s.replace('.', "_"))
} else {
p2
};
p1 = fastn_js::utils::name_to_js_(p1.as_str());
let mut wrapper_function = None;
while let Some(ref remaining) = p2 {
Expand Down Expand Up @@ -125,3 +130,15 @@ pub fn trim_brackets(s: &str) -> String {
pub(crate) fn kebab_to_snake_case(s: &str) -> String {
s.replace('-', "_")
}

pub(crate) fn ends_with_exact_suffix(name: &str, separator: &str, suffix: &str) -> bool {
if let Some((_, end)) = name.rsplit_once(separator) {
end.eq(suffix)
} else {
false
}
}

pub(crate) fn is_asset_path(name: &str) -> bool {
ends_with_exact_suffix(name, "/", "assets#files")
}
File renamed without changes.

0 comments on commit cdda10c

Please sign in to comment.