我试图理解JavaScript的OOP模型,所以我正在阅读这篇文章:https: //developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript
以下代码很有趣:
function Person(gender) {
this.gender = gender;
alert('Person instantiated');
}
Person.prototype.gender = '';
var person1 = new Person('Male');
var person2 = new Person('Female');
//display the person1 gender
alert('person1 is a ' + person1.gender); // person1 is a Male
Run Code Online (Sandbox Code Playgroud)
有趣而且不清楚的是这一行:
Person.prototype.gender = '';
Run Code Online (Sandbox Code Playgroud)
我不明白所以我用该行测试了代码,没有它.
代码在两种情况下都能正常工作.
所以我的问题是:
为什么作者添加该行?
像 googlemaps API 和 facebook API 这样的 API 是公开的,任何人都可以使用。所以我的问题是如何将 REST API 设为私有,以便它只能由选定的一个消费者使用。例如,您仅为您的 pwn AngularJS 应用程序制作 Rest API。这样做很常见吗?现实世界的方法是什么?在这方面,REST API 和 REST Web 服务之间有什么区别吗?
我有一个组件使用xtype="richtext"我的项目中的Rich Text Edit小部件(),它在整个站点中用作默认文本组件.
用户希望能够使用telURI方案将电话链接插入使用此组件输入的文本中.
该对话框允许他们这样做,但是当稍后在Sightly/HTL中呈现富文本编辑的内容时,将使用html上下文:
{$text @ context='html'}
Run Code Online (Sandbox Code Playgroud)
完成此操作后,将忽略my属性的值.
存储在存储库中的HTML是:
<a href="tel:04242424242">Call us!</a>
Run Code Online (Sandbox Code Playgroud)
在作者实例的页面上实际呈现的是:
<a>Call us!</a>
Run Code Online (Sandbox Code Playgroud)
在发布者上,由于链接检查器,标签会被完全删除.
更改上下文会unsafe导致href渲染,但这不是我愿意接受的解决方案.该组件在很多地方使用,我想确保XSS保护足够.
有没有办法影响htmlHTL中的上下文处理电话链接的方式?
我尝试在叠加层中添加一个额外的正则表达式apps/cq/xssprotection/config.xml:
<regexp name="onsiteURL" value="([\p{L}\p{N}\\\.\#@\$%\+&;\-_~,\?=/!]+|\#(\w)+)"/>
<regexp name="offsiteURL" value="(\s)*((ht|f)tp(s?)://|mailto:)[\p{L}\p{N}]+[\p{L}\p{N}\p{Zs}\.\#@\$%\+&;:\-_~,\?=/!]*(\s)*"/>
<regexp name="telephoneLink" value="tel:\+?[0-9]+"/>
Run Code Online (Sandbox Code Playgroud)
进一步说:
<attribute name="href">
<regexp-list>
<regexp name="onsiteURL"/>
<regexp name="offsiteURL"/>
<regexp name="telephoneLink"/>
</regexp-list>
<!-- Skipped for brevity -->
</attribute>
Run Code Online (Sandbox Code Playgroud)
但这似乎并没有影响Sightly/HTL在html上下文中转义字符串的方式.
我也试过覆盖Sling xss规则,/libs/sling/xss/config.xml但也没有运气.
怎么做到呢?
我试图在我的 JUnit 测试中使用 WireMock 来模拟对外部 API 的调用。
public class ExampleWiremockTest {
@Rule
public WireMockRule wireMockRule = new WireMockRule(9999);
@Before
public void setUp() {
stubFor(get(urlEqualTo("/bin/sillyServlet"))
.willReturn(aResponse()
.withStatus(200)
.withBody("Hello WireMock!")
)
);
}
@Test
public void testNothing() throws URISyntaxException, IOException {
URI uri = new URIBuilder().setScheme("http")
.setHost("localhost")
.setPort(9999)
.setPath("/bin/sillyServlet")
.build();
HttpGet httpGet = new HttpGet(uri);
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
String body = EntityUtils.toString(entity);
assertThat(body, is("Hello WireMock!"));
}
}
Run Code Online (Sandbox Code Playgroud)
代码可以编译,但是当我运行测试时,WireMock 抛出一个 HTTP 500,这似乎是由底层 Servlet API …
我使用Firebug的Inspect Element在网页中捕获XPath,它给了我类似的东西:
//*[@id="Search_Fields_profile_docno_input"]
Run Code Online (Sandbox Code Playgroud)
我在IE中使用Bookmarklets技术来捕获同一个对象的XPath,我有类似的东西:
//INPUT[@id='Search_Fields_profile_docno_input']
Run Code Online (Sandbox Code Playgroud)
请注意,第一个没有INPUT而是有一个星号(*).为什么我会得到不同的XPath表达式?我用于测试的哪一个是否重要:
Selenium.Click(//*[@id="Search_Fields_profile_docno_input"]);
Run Code Online (Sandbox Code Playgroud)
要么
Selenium.Click(//INPUT[@id='Search_Fields_profile_docno_input']);
Run Code Online (Sandbox Code Playgroud) public class ReplaceVowels {
public static void main(String args[]) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the String:");
String str = bf.readLine();
char[] c = new char[str.length()];
for (int i = 0; i < str.length(); i++) {
if (c[i] == 'a' || c[i] == 'e' || c[i] == 'i' || c[i] == 'o'
|| c[i] == 'u') {
System.out.println(str.replace(c[i], '?'));
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么这个str.replace方法不起作用?我该怎么做才能让它发挥作用?
我无法正确地将我的网站集中在一起
当我缩小时,它似乎居中.但对于不缩小的用户来说,它看起来不合适.有什么建议?该网站是使用所有AP div创建的,即使在尝试使用以下内容时它也无法正确居中:
<div align="center">
Run Code Online (Sandbox Code Playgroud) 我有一个包含item1和item2的jcombobox,我也有一个jtextfield ..当我在我的jcombobox上选择item1时,我希望30出现在我的jtextfield上,而如果选择了Item2则为40 ...我该怎么做?
我正在使用SitePrism来测试我的Web应用程序.我有许多扩展的类,SitePrism::Page许多经常使用的HTML片段由匹配的类扩展表示SitePrism::Section
class Login < SitePrism::Section
element :username, "#username"
element :password, "#password"
element :sign_in, "button"
end
class Home < SitePrism::Page
section :login, Login, "div.login"
end
Run Code Online (Sandbox Code Playgroud)
问题是,我正在处理的应用程序基于CMS,其中可以通过基于预定义内容选择模板然后将任意数量的可用组件拖放到页面上来组装页面.
最初的开发人员创建了一个Page Object来镜像每个可用的Template.只要测试数量很少并且我们不得不在我们的功能文件中测试的页面变体太多,这就没问题了.
随着多个测试用例的增加,页面对象开始以惊人的速度增长.
虽然我们可以通过为CMS中可用的每个组件定义Sections并在页面对象中重用它们来轻松地减轻代码重复,但是很多属性很少被使用.
class BlogPost < SitePrism::Page
section :logo, MySite::Components::Logo, '.logo'
section :navigation, MySite::Components::Navigation, '.primary-navigation'
section :header, MySite::Components::BlogHeader, '.header'
section :introduction, MySite::Components::Text, '.text .intro'
# and so on, a lot of dynamic staff that could potentially be dropped onto the page …Run Code Online (Sandbox Code Playgroud) 该schema.org网站给出了JSON-LD代表的面包屑的一个例子
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement":
[
{
"@type": "ListItem",
"position": 1,
"item":
{
"@id": "https://example.com/dresses",
"name": "Dresses"
}
},
{
"@type": "ListItem",
"position": 2,
"item":
{
"@id": "https://example.com/dresses/real",
"name": "Real Dresses"
}
}
]
}
</script>
Run Code Online (Sandbox Code Playgroud)
大部分内容对我来说都很清楚,但我对本示例中提供的链接的语义不是绝对确定。
我觉得令人困惑的是@id属性。它们的值是 URL,看起来这些应该指向由面包屑项目链接的实际网页。然而,属性的名称表明 URL 可能实际上指向某些本体中的概念标识符。是哪个?
“无标记”选项卡包含一段未注释的 HTML,这表明我的第一个猜测是正确的,并且 URL 实际上指向网页。
<ol>
<li>
<a href="https://example.com/dresses">Dresses</a>
</li>
<li>
<a href="https://example.com/dresses/real">Real Dresses</a>
</li>
</ol>
Run Code Online (Sandbox Code Playgroud)
是这种情况吗,在这种情况下可以使用相对 URL 吗?
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement":
[
{
"@type": "ListItem", …Run Code Online (Sandbox Code Playgroud) java ×3
aem ×1
api ×1
bookmarklet ×1
capybara ×1
css ×1
cucumber ×1
firebug ×1
htl ×1
html ×1
itemlistener ×1
javascript ×1
jcombobox ×1
jetty ×1
json-ld ×1
maven ×1
oop ×1
prototype ×1
rest ×1
ruby ×1
schema.org ×1
selenium ×1
sightly ×1
site-prism ×1
swing ×1
tel ×1
wiremock ×1
xpath ×1
xss ×1