kinow commented on code in PR #1746: URL: https://github.com/apache/jena/pull/1746#discussion_r1096731851
########## jena-fuseki2/jena-fuseki-ui/src/utils/query.js: ########## @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Utility functions for query components and views. + * + * Useful to separate code that can be easily tested without having to + * instantiate a complete component or view. + */ + +import queryString from 'query-string' + +/** + * Create a shareable link using the value of the SPARQL query in the + * YASQE editor and compose a safe link to be used in the browser. + * + * Based on YASGUI code, but modified to avoid parsing the Vue Route query + * hash. Note that we cannot use `document.location.hash` since it could + * contain the ?query=... too. Instead, we must use Vue Route path value. + * + * The query is escaped with the same code as YASGUI. + * + * @param {string} query + * @param {string} path + * @return {string} + */ +export function createShareableLink (query, path) { Review Comment: Moved this function out of the `Query.vue` Vue.js view, because it would be easier to test it that way instead of writing a complete e2e or unit test. ########## jena-fuseki2/jena-fuseki-ui/src/utils/query.js: ########## @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Utility functions for query components and views. + * + * Useful to separate code that can be easily tested without having to + * instantiate a complete component or view. + */ + +import queryString from 'query-string' + +/** + * Create a shareable link using the value of the SPARQL query in the + * YASQE editor and compose a safe link to be used in the browser. + * + * Based on YASGUI code, but modified to avoid parsing the Vue Route query + * hash. Note that we cannot use `document.location.hash` since it could + * contain the ?query=... too. Instead, we must use Vue Route path value. + * + * The query is escaped with the same code as YASGUI. + * + * @param {string} query + * @param {string} path + * @return {string} + */ +export function createShareableLink (query, path) { Review Comment: Also made it receive directly a query and a path, instead of tying it up with YASQE object. Then in the view we just create a curried function that extracts the query from YASQE, and hoists the path from Vue Router. ########## jena-fuseki2/jena-fuseki-ui/tests/unit/components/serverstatus.vue.spec.js: ########## @@ -33,7 +33,6 @@ describe('ServerStatus', () => { mocks: { $fusekiService: { async getServerStatus () { - console.log('Hola!') Review Comment: Sorry! I had noticed these console log lines, but I thought I had intentionally written that somewhere... but searching it revealed I had simply forgotten to remove this debug line :bow: ########## jena-fuseki2/jena-fuseki-ui/src/utils/query.js: ########## @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Utility functions for query components and views. + * + * Useful to separate code that can be easily tested without having to + * instantiate a complete component or view. + */ + +import queryString from 'query-string' + +/** + * Create a shareable link using the value of the SPARQL query in the + * YASQE editor and compose a safe link to be used in the browser. + * + * Based on YASGUI code, but modified to avoid parsing the Vue Route query + * hash. Note that we cannot use `document.location.hash` since it could + * contain the ?query=... too. Instead, we must use Vue Route path value. + * + * The query is escaped with the same code as YASGUI. + * + * @param {string} query + * @param {string} path + * @return {string} + */ +export function createShareableLink (query, path) { + return ( + document.location.protocol + + '//' + + document.location.host + + document.location.pathname + + document.location.search + + '#' + + path + + '?' + + // Same as YASGUI does, good idea to avoid security problems... + queryString.stringify({ query }) Review Comment: @SimonBin 's fix is here :point_up: :clap: -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
